Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:io.dropwizard.primer.auth.PrimerAuthenticatorRequestFilter.java

private void handleException(Throwable e, ContainerRequestContext requestContext, String token)
        throws JsonProcessingException {
    if (e.getCause() instanceof TokenExpiredException || e instanceof TokenExpiredException) {
        log.error("Token Expiry Error: {}", e.getMessage());
        requestContext.abortWith(Response.status(Response.Status.PRECONDITION_FAILED)
                .entity(objectMapper/*from w ww . ja va  2  s  .  c om*/
                        .writeValueAsBytes(PrimerError.builder().errorCode("PR003").message("Expired").build()))
                .build());
    } else if (e.getCause() instanceof MalformedJsonWebTokenException
            || e instanceof MalformedJsonWebTokenException) {
        log.error("Token Malformed Error: {}", e.getMessage());
        requestContext
                .abortWith(Response.status(Response.Status.UNAUTHORIZED)
                        .entity(objectMapper.writeValueAsBytes(
                                PrimerError.builder().errorCode("PR004").message("Unauthorized").build()))
                        .build());
    } else if (e.getCause() instanceof InvalidSignatureException || e instanceof InvalidSignatureException) {
        log.error("Token Signature Error: {}", e.getMessage());
        requestContext
                .abortWith(Response.status(Response.Status.UNAUTHORIZED)
                        .entity(objectMapper.writeValueAsBytes(
                                PrimerError.builder().errorCode("PR004").message("Unauthorized").build()))
                        .build());
    } else if (e.getCause() instanceof FeignException) {
        log.error("Feign error: {}", e.getMessage());
        handleError(Response.Status.fromStatusCode(((FeignException) e.getCause()).status()), "PR000",
                e.getCause().getMessage(), token, requestContext);

    } else if (e instanceof FeignException) {
        log.error("Feign error: {}", e.getMessage());
        handleError(Response.Status.fromStatusCode(((FeignException) e).status()), "PR000", e.getMessage(),
                token, requestContext);
    } else if (e.getCause() instanceof PrimerException) {
        log.error("Primer error: {}", e.getMessage());
        handleError(Response.Status.fromStatusCode(((PrimerException) e.getCause()).getStatus()),
                ((PrimerException) e.getCause()).getErrorCode(), e.getCause().getMessage(), token,
                requestContext);
    } else if (e instanceof PrimerException) {
        log.error("Primer error: {}", e.getMessage());
        handleError(Response.Status.fromStatusCode(((PrimerException) e).getStatus()),
                ((PrimerException) e).getErrorCode(), e.getMessage(), token, requestContext);
    } else {
        log.error("General error: {}", e);
        handleError(Response.Status.INTERNAL_SERVER_ERROR, "PR000", "Error", token, requestContext);
    }
}

From source file:org.fornax.cartridges.sculptor.framework.web.errorhandling.ExceptionAdvice.java

protected ValidationException unwrapValidationException(Throwable throwable) {
    if (throwable == null) {
        return null;
    } else if (throwable instanceof ValidationException) {
        return (ValidationException) throwable;
    } else if (throwable.getCause() != null) {
        // recursive call to unwrap the cause
        return unwrapValidationException(throwable.getCause());
    } else {//w ww  .j a  v  a2 s.c o m
        // didn't find any ValidationException in the cause stack
        return null;
    }
}

From source file:gov.nih.nci.integration.caaers.invoker.CaAERSAdverseEventServiceInvocationStrategy.java

private void handleException(ServiceInvocationResult result) {
    if (!result.isFault()) {
        return;/*  ww w  .  j  ava2s.co m*/
    }

    final Exception exception = result.getInvocationException();
    Throwable cause = exception;
    while (cause instanceof IntegrationException) {
        cause = cause.getCause();
    }
    if (cause == null) {
        return;
    }

    final String[] throwableMsgs = getThrowableMsgs(cause);
    IntegrationException newie = (IntegrationException) exception;

    final Set<String> keys = msgToErrMap.keySet();

    for (String lkupStr : keys) {
        final String msg = getMatchingMsg(lkupStr, throwableMsgs);
        if (msg != null) {
            newie = new IntegrationException(msgToErrMap.get(lkupStr), cause, msg);
            break;
        }
    }

    result.setInvocationException(newie);
}

From source file:jp.co.opentone.bsol.linkbinder.view.exception.LinkBinderExceptionHandler.java

private boolean isViewExpiredException(Throwable t) {
    return t instanceof ViewExpiredException
            || (t.getCause() != null && t.getCause() instanceof ViewExpiredException);
}

From source file:ch.cyberduck.core.threading.BackgroundException.java

/**
 * @return The real cause of the exception thrown
 *//*  ww w  . j av a  2 s  .  co m*/
@Override
public Throwable getCause() {
    final Throwable cause = super.getCause();
    if (null == cause) {
        return this;
    }
    Throwable root = cause.getCause();
    if (null == root) {
        return cause;
    }
    while (root.getCause() != null) {
        root = root.getCause();
    }
    if (StringUtils.isNotBlank(root.getMessage())) {
        return root;
    }
    return cause;
}

From source file:de.appsolve.padelcampus.reporting.ErrorReporter.java

public void notify(Throwable ex) {
    boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString()
            .contains("jdwp");
    if (!isDebug) {
        if (ex != null && !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getClass().getSimpleName())) {
            if (ex.getCause() == null
                    || !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getCause().getClass().getSimpleName())) {
                try {
                    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder
                            .currentRequestAttributes();
                    //log all errors when we don't have a request context, e.g. for scheduled tasks etc
                    if (attr == null || attr.getRequest() == null) {
                        LOG.error(ex.getMessage(), ex);
                    } else {
                        //if we have a request context, ignore bot requests
                        String userAgent = attr.getRequest().getHeader(HttpHeaders.USER_AGENT);
                        if (!StringUtils.isEmpty(userAgent)
                                && !IGNORED_USER_AGENT_PATTERN.matcher(userAgent).matches()) {
                            bugsnag.notify(ex);
                        }/*from  w w  w  .j  a  v  a  2 s. c  o  m*/
                    }
                } catch (IllegalStateException e) {
                    LOG.error(ex.getMessage(), ex);
                }

            }
        }
    }
}

From source file:org.fornax.cartridges.sculptor.framework.web.errorhandling.ExceptionAdvice.java

protected OptimisticLockingException unwrapOptimisticLockingException(Throwable throwable) {
    if (throwable == null) {
        return null;
    } else if (throwable instanceof OptimisticLockingException) {
        return (OptimisticLockingException) throwable;
    } else if (throwable.getCause() != null) {
        // recursive call to unwrap the cause
        return unwrapOptimisticLockingException(throwable.getCause());
    } else {//from w w  w . j a  va  2s.c  o m
        // didn't find any OptimisticLockingException in the cause stack
        return null;
    }
}

From source file:org.datacleaner.actions.DownloadFilesActionListener.java

public FileObject[] getFiles() throws SSLPeerUnverifiedException, IllegalStateException, RuntimeException {
    try {// w ww . ja va2 s.  c o m
        get();
    } catch (Throwable e) {
        if (e instanceof ExecutionException) {
            e = e.getCause();
        }
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        if (e instanceof SSLPeerUnverifiedException) {
            throw (SSLPeerUnverifiedException) e;
        }
        throw new IllegalStateException(e);
    }
    return _files;
}

From source file:edu.duke.cabig.c3pr.utils.DaoTestCase.java

private void endSession() {
    log.info("--    ending DaoTestCase interceptor session --");
    OpenSessionInViewInterceptor interceptor = findOpenSessionInViewInterceptor();
    try {//from ww w  .j ava 2 s . c  om
        if (shouldFlush) {
            interceptor.postHandle(webRequest, null);
        }
    } catch (RuntimeException exception) {
        if (exception instanceof HibernateJdbcException) {
            if (exception != null) {
                System.out.println(exception); // Log the exception
                // Get cause if present
                Throwable t = ((HibernateJdbcException) exception).getRootCause();

                while (t != null) {
                    System.out.println("*************Cause: " + t);
                    t = t.getCause();
                }

            }
        }
        throw exception;
    } finally {
        interceptor.afterCompletion(webRequest, null);
    }
}