List of usage examples for org.apache.commons.lang.exception ExceptionUtils indexOfThrowable
public static int indexOfThrowable(Throwable throwable, Class clazz)
Returns the (zero based) index of the first Throwable
that matches the specified class (exactly) in the exception chain.
From source file:com.jaspersoft.jasperserver.war.util.JSExceptionUtils.java
@SuppressWarnings("unchecked") public static <E extends Throwable> E extractCause(Throwable exception, Class<E> exceptionType) { int index = ExceptionUtils.indexOfThrowable(exception, exceptionType); E e;//from www. j a v a2 s. c o m if (index >= 0) { e = (E) ExceptionUtils.getThrowableList(exception).get(index); } else { e = null; } return e; }
From source file:net.shopxx.FreeMarkerExceptionHandler.java
public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException { if (ExceptionUtils.indexOfThrowable(te, IllegalLicenseException.class) >= 0) { throw new IllegalLicenseException(); }/* w w w.j ava2 s.c o m*/ DEFAULT_TEMPLATE_EXCEPTION_HANDLER.handleTemplateException(te, env, out); }
From source file:com.puyuntech.flowerToHome.FreeMarkerExceptionHandler.java
/** * ??/* w w w. j a va 2 s. c o m*/ * * @param te * ? * @param env * ?? * @param out * */ public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException { if (ExceptionUtils.indexOfThrowable(te, IllegalLicenseException.class) >= 0) { throw new IllegalLicenseException(); } DEFAULT_TEMPLATE_EXCEPTION_HANDLER.handleTemplateException(te, env, out); }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaTimer.java
protected void handleOnTimerException(RuntimeException e) { int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class); if (reIdx > -1) { RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx); for (RemoteException.Cause cause : re.getCauses()) { //noinspection ThrowableResultOfMethodCallIgnored if (cause.getThrowable() instanceof NoUserSessionException) { log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId()); stop();//www . j av a2s.com break; } } } else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) { log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId()); stop(); } throw e; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimer.java
protected void handleTimerException(RuntimeException ex) { if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) { // If a ConnectException occurred, just log it and ignore log.warn("onTimer error: " + ex.getMessage()); } else {/*from w w w . j ava 2 s.c om*/ // Otherwise throw the exception, but first search for NoUserSessionException in chain, // if found - stop the timer int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class); if (reIdx > -1) { RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx); for (RemoteException.Cause cause : re.getCauses()) { //noinspection ThrowableResultOfMethodCallIgnored if (cause.getThrowable() instanceof NoUserSessionException) { log.warn("NoUserSessionException in timer, timer will be stopped"); disposeTimer(); break; } } } else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) { log.warn("NoUserSessionException in timer, timer will be stopped"); disposeTimer(); } throw ex; } }
From source file:com.facultyshowcase.app.ui.ProfessorProfileApp.java
/** * Setup the editor by creating the View and wiring in the necessary * controls for persistence with our DAO. * * @param ProfessorProfile the user profile. *//*from w ww. ja v a 2 s . c o m*/ void setupEditor(final ProfessorProfile ProfessorProfile) { getActiveSearchUI().getWorkspace().addUITask(new AbstractUITask("upe#" + ProfessorProfile.getId()) { @Override public LocalizedText getLabel(LocaleContext localeContext) { return new LocalizedText("User Profile - " + _getName(EntityRetriever.getInstance().reattachIfNecessary(ProfessorProfile))); } @Override public Component createTaskUI(LocaleContext localeContext) { ReflectiveAction saveAction = CommonActions.SAVE.defaultAction(); ReflectiveAction cancelAction = CommonActions.CANCEL.defaultAction(); PropertyEditor<ProfessorProfile> propertyEditor = new PropertyEditor<>(); propertyEditor .setTitle(new Label(TextSources.create("User Profile")).setHTMLElement(HTMLElement.h2)); propertyEditor.setValueEditor(new ProfessorProfileEditor(ProfessorProfile)); propertyEditor.setPersistenceActions(saveAction, cancelAction); // We are creating the action logic after creating the UI components /// so we can reference the component variables in the actions. cancelAction.setActionListener(event -> { // When the cancelAction is executed, close the editor UI /// the switch to the viewer UI. // If we want to warn the user about unsaved changes, then /// we could check the ModificationState of the editor before /// proceeding. propertyEditor.close(); setupViewer(EntityRetriever.getInstance().reattachIfNecessary(ProfessorProfile)); }); saveAction.setActionListener(event -> { // If the user presses one of the save buttons, then /// validate that the data captured in the UI is valid /// before attempting to save the changes. /// Any validation errors will be added to the notifiable. if (propertyEditor.validateValue()) { boolean success = false; try { if (propertyEditor.getModificationState().isModified()) { // Editor indicated data is valid, commit the UI /// data to the ProfessorProfile and attempt to save it. final ProfessorProfile commitValue = propertyEditor.commitValue(); assert commitValue != null; _ProfessorProfileDAO.saveProfessorProfile(commitValue); success = true; } else success = true; } catch (Exception e) { if (ExceptionUtils.indexOfThrowable(e, ConstraintViolationException.class) > 0) { _logger.error("Constraint violation", e); // Let the user know that something bad happened. propertyEditor.getNotifiable() .sendNotification(NotificationImpl.create(e, "Username already in use.")); } else { _logger.error("Unexpected error committing changes", e); // Let the user know that something bad happened. propertyEditor.getNotifiable().sendNotification( NotificationImpl.create(e, "I'm sorry, I was unable to save.")); } } if (success) { // Save was successful. We're executing the cancelAction /// since it switches us to the viewer UI. cancelAction.actionPerformed(event); } } }); return propertyEditor; } }); }
From source file:mp.platform.cyclone.webservices.utils.server.PaymentHelper.java
/** * Returns the payment status that corresponds to the given error *///w ww . j a v a 2 s.c o m public PaymentStatus toStatus(final Throwable error) { if (error instanceof InvalidCredentialsException || error instanceof InvalidPosPinException) { return PaymentStatus.INVALID_CREDENTIALS; } else if (error instanceof BlockedCredentialsException || error instanceof PosPinBlockedException) { return PaymentStatus.BLOCKED_CREDENTIALS; } else if (error instanceof NotEnoughCreditsException) { return PaymentStatus.NOT_ENOUGH_CREDITS; } else if (error instanceof UpperCreditLimitReachedException) { return PaymentStatus.RECEIVER_UPPER_CREDIT_LIMIT_REACHED; } else if (error instanceof MaxAmountPerDayExceededException) { return PaymentStatus.MAX_DAILY_AMOUNT_EXCEEDED; } else if (error instanceof ValidationException || error instanceof UnexpectedEntityException || error instanceof EntityNotFoundException || error instanceof UserNotFoundException) { return PaymentStatus.INVALID_PARAMETERS; } else if (ExceptionUtils.indexOfThrowable(error, DataIntegrityViolationException.class) != -1) { return PaymentStatus.INVALID_PARAMETERS; } else { return PaymentStatus.UNKNOWN_ERROR; } }
From source file:com.jaspersoft.jasperserver.api.metadata.olap.service.impl.OlapConnectionServiceImpl.java
protected mondrian.olap.Connection getMondrianConnection(ExecutionContext context, MondrianConnection conn, ReportDataSource dataSource) {/*from w ww . j a va 2s .c o m*/ Util.PropertyList connectProps = getMondrianConnectProperties(context, conn, dataSource); try { return DriverManager.getConnection(connectProps, repositoryCatalogLocator); } catch (MondrianException e) { String dataSourceString = connectProps.get(OLAP_CONNECTION_JNDI_DATA_SOURCE); if (ExceptionUtils.indexOfThrowable(e, NoInitialContextException.class) > 0 && dataSourceString != null) { Map<String, String> jdbcProperties = jndiFallbackResolver.getJdbcPropertiesMap(dataSourceString); try { // Remove JNDI reference. connectProps.remove(OLAP_CONNECTION_JNDI_DATA_SOURCE); // Add JDBC url, username and password. connectProps.put(OLAP_CONNECTION_JDBC, jdbcProperties.get(JndiFallbackResolver.JDBC_URL)); connectProps.put(OLAP_CONNECTION_JDBC_USER, jdbcProperties.get(JndiFallbackResolver.JDBC_USERNAME)); connectProps.put(OLAP_CONNECTION_JDBC_PASSWORD, jdbcProperties.get(JndiFallbackResolver.JDBC_PASSWORD)); return DriverManager.getConnection(connectProps, repositoryCatalogLocator); } catch (Throwable t) { throw new JSException("Error getting connection from jndi fallback properties.", t); } } else { throw e; } } }
From source file:beans.ServerBootstrapperImpl.java
@Override public ServerNode bootstrapCloud(ServerNode serverNode) { serverNode.setRemote(true);//from www. ja v a 2s.c o m // get existing management machine List<Server> existingManagementMachines = null; try { existingManagementMachines = getAllMachinesWithPredicate(new ServerNamePrefixPredicate(), new NovaContext(conf.server.cloudBootstrap.cloudProvider, serverNode.getProject(), serverNode.getKey(), serverNode.getSecretKey(), conf.server.cloudBootstrap.zoneName, true)); } catch (Exception e) { if (ExceptionUtils.indexOfThrowable(e, AuthorizationException.class) > 0) { serverNode.errorEvent("Invalid Credentials").save(); return null; } logger.error("unrecognized exception, assuming only existing algorithm failed. ", e); } logger.info("found [{}] management machines", CollectionUtils.size(existingManagementMachines)); if (!CollectionUtils.isEmpty(existingManagementMachines)) { Server managementMachine = CollectionUtils.first(existingManagementMachines); // GUY - for some reason // ((Address )managementMachine.getAddresses().get("private").toArray()[1]).getAddr() Utils.ServerIp serverIp = Utils.getServerIp(managementMachine); if (!cloudifyRestClient.testRest(serverIp.publicIp).isSuccess()) { serverNode.errorEvent("Management machine exists but unreachable").save(); logger.info("unable to reach management machine. stopping progress."); return null; } logger.info("using first machine [{}] with ip [{}]", managementMachine, serverIp); serverNode.setServerId(managementMachine.getId()); serverNode.infoEvent("Found management machine on :" + serverIp).save(); serverNode.setPublicIP(serverIp.publicIp); serverNode.save(); logger.info("not searching for key - only needed for bootstrap"); } else { logger.info("did not find an existing management machine, creating new machine"); createNewMachine(serverNode); } return serverNode; }
From source file:com.jaspersoft.jasperserver.war.action.ReportExecutionController.java
protected void handleReportUpdateError(HttpServletResponse res, ReportExecutionStatus reportStatus) throws Exception { Throwable error = reportStatus.getError(); if (log.isDebugEnabled()) { log.debug("report error " + error);// only message }// w w w . j a va2 s .c o m // set a header so that the UI knows it's a report execution error res.setHeader("reportError", "true"); // set as a header because we don't have other way to pass it res.setHeader("lastPartialPageIndex", Integer.toString(reportStatus.getCurrentPageCount() - 1)); // throw an exception to get to the error page if (error instanceof Exception) { // copied from ViewReportAction.executeReport // note that the message is not localized int indexIO = ExceptionUtils.indexOfThrowable(error, IOException.class); if (indexIO != -1) { Exception sourceException = (Exception) ExceptionUtils.getThrowableList(error).get(indexIO); throw new JSShowOnlyErrorMessage(sourceException.getMessage()); } throw (Exception) error; } throw new JSException("jsexception.view.report.error", error); }