List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCause
public static Throwable getRootCause(final Throwable throwable)
Introspects the Throwable
to obtain the root cause.
This method walks through the exception chain to the last element, "root" of the tree, using #getCause(Throwable) , and returns that exception.
From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops.
From source file:com.thinkbiganalytics.nifi.rest.client.NifiRestClientExceptionTranslator.java
public static Throwable translateException(Throwable e) { //Return if its already translated to a NifiClientRuntimeException if (e instanceof NifiClientRuntimeException) { return e; }// www . j av a 2s. c om if (e instanceof NotFoundException) { return new NifiComponentNotFoundException(e.getMessage()); } else if (e instanceof NullPointerException) { return new NifiConnectionException("Verify NiFi is running and try again", e); } else if (e instanceof ProcessingException) { int throwables = ExceptionUtils.getThrowableCount(e); if (throwables > 1) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause instanceof NoHttpResponseException || rootCause instanceof HttpHostConnectException || rootCause instanceof ConnectException) { //connection error return new NifiConnectionException(e.getMessage(), e); } } } return new NifiClientRuntimeException(e); }
From source file:name.martingeisse.gargl.application.wicket.GarglExceptionMapper.java
@Override public IRequestHandler map(Exception e) { try {/* w ww. ja v a 2 s .c o m*/ // we're not interested in wrapping exceptions, so get the original one Throwable originalException = ExceptionUtils.getRootCause(e); // disable caching for error pages final Response response = RequestCycle.get().getResponse(); if (response instanceof WebResponse) { ((WebResponse) response).disableCaching(); } // check for specific exceptions if (originalException instanceof PermissionDeniedException) { // return new RenderPageRequestHandler(new PageProvider(PermissionDeniedPage.class), RedirectPolicy.ALWAYS_REDIRECT); } } catch (final RuntimeException e2) { // log this exception, then use default mapping for the original exception logger.error("nested exception in GarglExceptionMapper", e2); } // fall back to default beahvior return super.map(e); }
From source file:name.martingeisse.guiserver.application.wicket.GuiExceptionMapper.java
@Override public IRequestHandler map(Exception e) { try {//from w ww.j a v a 2 s . c o m // we're not interested in wrapping exceptions, so get the original one Throwable originalException = ExceptionUtils.getRootCause(e); // disable caching for error pages final Response response = RequestCycle.get().getResponse(); if (response instanceof WebResponse) { ((WebResponse) response).disableCaching(); } // check for specific exceptions if (originalException instanceof PermissionDeniedException) { // return new RenderPageRequestHandler(new PageProvider(PermissionDeniedPage.class), RedirectPolicy.ALWAYS_REDIRECT); } } catch (final RuntimeException e2) { // log this exception, then use default mapping for the original exception logger.error("nested exception in GuiExceptionMapper", e2); } // fall back to default beahvior return super.map(e); }
From source file:name.martingeisse.slave_services.application.wicket.SlaveServicesExceptionMapper.java
@Override public IRequestHandler map(Exception e) { try {/*w w w.jav a 2s .c o m*/ // we're not interested in wrapping exceptions, so get the original one Throwable originalException = ExceptionUtils.getRootCause(e); // disable caching for error pages final Response response = RequestCycle.get().getResponse(); if (response instanceof WebResponse) { ((WebResponse) response).disableCaching(); } // check for specific exceptions if (originalException instanceof PermissionDeniedException) { // return new RenderPageRequestHandler(new PageProvider(PermissionDeniedPage.class), RedirectPolicy.ALWAYS_REDIRECT); } } catch (final RuntimeException e2) { // log this exception, then use default mapping for the original exception logger.error("nested exception in SlaveServicesExceptionMapper", e2); } // fall back to default beahvior return super.map(e); }
From source file:com.github.ibole.infrastructure.common.exception.MoreThrowables.java
/** * Get root cause stack trace as string. * @param cause Throwable/*w w w . jav a 2s . co m*/ * @return the string of root cause stack trace */ public static String getRootCauseStackTraceAsString(Throwable cause) { return getStackTraceAsString(ExceptionUtils.getRootCause(cause)); }
From source file:ch.cyberduck.core.azure.AzureExceptionMappingService.java
@Override public BackgroundException map(final StorageException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if (ExceptionUtils.getRootCause(e) instanceof UnknownHostException) { return new NotfoundException(buffer.toString(), e); }//w ww. j a v a 2s .c o m switch (e.getHttpStatusCode()) { case 403: return new LoginFailureException(buffer.toString(), e); case 404: return new NotfoundException(buffer.toString(), e); case 304: case 405: case 400: case 411: case 412: return new InteroperabilityException(buffer.toString(), e); case 500: // InternalError // OperationTimedOut return new ConnectionTimeoutException(buffer.toString(), e); case 503: // ServerBusy return new RetriableAccessDeniedException(buffer.toString(), e); } return this.wrap(e, buffer); }
From source file:de.tuberlin.uebb.jbop.exception.JBOPClassExceptionTest.java
/** * Test creation of {@link JBOPClassException}. *///from w w w.j a v a2 s. co m @Test public void testJBOPClassException() { final JBOPClassException jBOPClassException = new JBOPClassException(message, cause); try { throw jBOPClassException; } catch (final Throwable jce) { assertEquals(jce.getClass().getSimpleName() + ": " + message, ExceptionUtils.getMessage(jce)); assertEquals(cause, ExceptionUtils.getRootCause(jce)); } }
From source file:ch.cyberduck.core.onedrive.OneDriveExceptionMappingService.java
@Override public BackgroundException map(final OneDriveAPIException failure) { if (failure.getResponseCode() > 0) { final StringAppender buffer = new StringAppender(); buffer.append(failure.getMessage()); buffer.append(failure.getErrorMessage()); return new HttpResponseExceptionMappingService() .map(new HttpResponseException(failure.getResponseCode(), buffer.toString())); }/*from ww w .j a v a 2 s. com*/ if (ExceptionUtils.getRootCause(failure) instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure)); } return new InteroperabilityException(failure.getMessage(), failure); }
From source file:com.francetelecom.clara.cloud.presentation.ExceptionViewFactory.java
public ExceptionView newView(Exception e) { Throwable rootCause = (ExceptionUtils.getRootCause(e) != null ? ExceptionUtils.getRootCause(e) : e); if (rootCause instanceof AuthorizationException) { return webPageFactory.getAuthorizationExceptionPage(); }/* w w w . j a v a 2s . c o m*/ if (rootCause instanceof InvalidApplicationException) { return webPageFactory.getInvalidApplicationExceptionPage(); } if (rootCause instanceof InvalidReleaseException) { return webPageFactory.getInvalidReleaseExceptionPage(); } if (rootCause instanceof ObjectNotFoundException) { return webPageFactory.getObjectNotFoundExceptionPage(); } if (rootCause instanceof WicketRuntimeException && rootCause.getMessage() != null && rootCause.getMessage().contains("Pagemap null is still locked")) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); logger.debug("dumping threads for page map issue"); logger.debug(threadMXBean.dumpAllThreads(true, true).toString()); return webPageFactory.getUnknownExceptionPage(); } return webPageFactory.getUnknownExceptionPage(); }
From source file:com.heliosmi.portal.aspect.LoggingAspect.java
@Around("allBeans()") public Object profiler(ProceedingJoinPoint pjp) throws Throwable { long start = System.nanoTime(); String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName(); log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs())); Object returnValue = null;//from w w w .ja v a 2s . co m try { returnValue = pjp.proceed(); } catch (Exception exception) { log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception))); log.error(ExceptionUtils.getStackTrace(exception)); throw exception; } long end = System.nanoTime(); log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. "); return returnValue; }