List of usage examples for org.apache.commons.lang.exception ExceptionUtils getThrowables
public static Throwable[] getThrowables(Throwable throwable)
Returns the list of Throwable
objects in the exception chain.
A throwable without cause will return an array containing one element - the input throwable.
From source file:com.vladmihalcea.concurrent.aop.OptimisticConcurrencyControlAspect.java
private boolean isRetryThrowable(Throwable throwable, Class<? extends Throwable>[] retryOn) { Throwable[] causes = ExceptionUtils.getThrowables(throwable); for (Throwable cause : causes) { for (Class<? extends Throwable> retryThrowable : retryOn) { if (retryThrowable.isAssignableFrom(cause.getClass())) { return true; }/* w ww.j a v a 2 s . c om*/ } } return false; }
From source file:mitm.djigzo.web.common.RedirectRequestExceptionHandler.java
@SuppressWarnings("unchecked") @Override//from w w w . jav a 2 s . c o m public void handleRequestException(Throwable t) throws IOException { boolean handled = false; /* * Check for specified exception */ int exceptionIndex = ExceptionUtils.indexOfType(t, exceptionClass); if (exceptionIndex != -1) { /* * Check if the exception is caused by authentication failure. */ T exception = (T) ExceptionUtils.getThrowables(t)[exceptionIndex]; if (isMatch(exception)) { logger.warn("Exception " + exceptionClass + " handled. Redirecting to page: " + redirectToPage); Link pageLink = linkFactory.createPageRenderLink(redirectToPage, false, context); response.sendRedirect(pageLink.toRedirectURI()); handled = true; } } if (!handled) { /* * Pass the exception to the next handler */ ((RequestExceptionHandler) delegate).handleRequestException(t); } }
From source file:gov.nih.nci.integration.caaers.invoker.CaAERSAdverseEventServiceInvocationStrategy.java
private String[] getThrowableMsgs(Throwable cause) { final Throwable[] throwables = ExceptionUtils.getThrowables(cause); String[] msgs = new String[throwables.length]; for (int i = 0; i < throwables.length; i++) { msgs[i] = throwables[i].getMessage(); }//from ww w . j a v a2s. c om return msgs; }
From source file:nl.strohalm.cyclos.utils.ExceptionHelper.java
private static boolean isLockingException(final Throwable t, final boolean recurse) { if (t instanceof LockingException || t instanceof LockAcquisitionException || t instanceof PessimisticLockException) { return true; }// w w w . j ava 2 s . c o m if (t instanceof SQLException) { final SQLException e = (SQLException) t; return e.getErrorCode() == ER_LOCK_WAIT_TIMEOUT || ST_LOCK.equals(e.getSQLState()); } if (recurse) { for (final Throwable thr : ExceptionUtils.getThrowables(t)) { if (isLockingException(thr, false)) { return true; } } } return false; }
From source file:org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverRemoteAcceptor.java
private List<Result> send(final String gremlin) throws SaslException { try {/*from www .j a v a2 s .c o m*/ return this.currentClient.submitAsync(gremlin, aliases, Collections.emptyMap()).get().all() .get(this.timeout, TimeUnit.MILLISECONDS); } catch (TimeoutException ignored) { throw new IllegalStateException( "Request timed out while processing - increase the timeout with the :remote command"); } catch (Exception e) { // handle security error as-is and unwrapped final Optional<Throwable> throwable = Stream.of(ExceptionUtils.getThrowables(e)) .filter(t -> t instanceof SaslException).findFirst(); if (throwable.isPresent()) throw (SaslException) throwable.get(); throw new IllegalStateException(e.getMessage(), e); } }
From source file:org.apache.tinkerpop.gremlin.console.jsr223.DriverRemoteAcceptor.java
private List<Result> send(final String gremlin) throws SaslException { try {//from ww w .j a v a 2 s .c om final ResultSet rs = this.currentClient.submitAsync(gremlin, aliases, Collections.emptyMap()).get(); return timeout > NO_TIMEOUT ? rs.all().get(timeout, TimeUnit.MILLISECONDS) : rs.all().get(); } catch (TimeoutException ignored) { throw new IllegalStateException( "Request timed out while processing - increase the timeout with the :remote command"); } catch (Exception e) { // handle security error as-is and unwrapped final Optional<Throwable> throwable = Stream.of(ExceptionUtils.getThrowables(e)) .filter(t -> t instanceof SaslException).findFirst(); if (throwable.isPresent()) throw (SaslException) throwable.get(); throw new IllegalStateException(e.getMessage(), e); } }
From source file:org.cleverbus.core.common.exception.ExceptionTranslator.java
/** * Returns recursively error messages from the whole exception hierarchy. * * @param ex the exception/*from w w w . j a v a 2 s.com*/ * @return exception message */ private static String getMessagesInExceptionHierarchy(Throwable ex) { Assert.notNull(ex, "the ex must not be null"); // use a util that can handle recursive cause structure: Throwable[] hierarchy = ExceptionUtils.getThrowables(ex); StringBuilder messages = new StringBuilder(); for (Throwable throwable : hierarchy) { if (messages.length() > 0) { messages.append(" => "); } messages.append(throwable.getClass().getSimpleName()).append(": ").append(throwable.getMessage()); } return messages.toString(); }
From source file:org.craftercms.security.impl.processors.SecurityExceptionProcessor.java
/** * Returns the security exception, if any, inside the specified's exception stack trace. *///from w w w . j a v a 2 s . c o m public CrafterSecurityException findSecurityException(Exception topException) { Throwable[] exceptionChain = ExceptionUtils.getThrowables(topException); for (Throwable e : exceptionChain) { if (e instanceof CrafterSecurityException) { return (CrafterSecurityException) e; } } return null; }
From source file:org.dllearner.cli.CLI.java
/** * Find the primary cause of the specified exception. * * @param e The exception to analyze// ww w .j a v a 2 s . c o m * @return The primary cause of the exception. */ private static Throwable findPrimaryCause(Exception e) { // The throwables from the stack of the exception Throwable[] throwables = ExceptionUtils.getThrowables(e); //Look For a Component Init Exception and use that as the primary cause of failure, if we find it int componentInitExceptionIndex = ExceptionUtils.indexOfThrowable(e, ComponentInitException.class); Throwable primaryCause; if (componentInitExceptionIndex > -1) { primaryCause = throwables[componentInitExceptionIndex]; } else { //No Component Init Exception on the Stack Trace, so we'll use the root as the primary cause. primaryCause = ExceptionUtils.getRootCause(e); } return primaryCause; }
From source file:org.dllearner.cli.unife.CLIDistributedLEAP.java
/** * Find the primary cause of the specified exception. * * @param e The exception to analyze//from w ww .j a va 2 s . c o m * @return The primary cause of the exception. */ protected static Throwable findPrimaryCause(Exception e) { // The throwables from the stack of the exception Throwable[] throwables = ExceptionUtils.getThrowables(e); //Look For a Component Init Exception and use that as the primary cause of failure, if we find it int componentInitExceptionIndex = ExceptionUtils.indexOfThrowable(e, ComponentInitException.class); Throwable primaryCause; if (componentInitExceptionIndex > -1) { primaryCause = throwables[componentInitExceptionIndex]; } else { //No Component Init Exception on the Stack Trace, so we'll use the root as the primary cause. primaryCause = ExceptionUtils.getRootCause(e); } return primaryCause; }