Example usage for org.apache.commons.lang3.exception ExceptionUtils getThrowableList

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getThrowableList

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getThrowableList.

Prototype

public static List<Throwable> getThrowableList(Throwable throwable) 

Source Link

Document

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return a list containing one element - the input throwable.

Usage

From source file:ch.cyberduck.core.worker.DefaultExceptionMappingService.java

@Override
public BackgroundException map(final Throwable failure) {
    final StringBuilder buffer = new StringBuilder();
    if (failure instanceof RuntimeException) {
        this.append(buffer, "Unknown application error");
    }//from  www .j av a  2s  .  c  o m
    this.append(buffer, failure.getMessage());
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (!StringUtils.contains(failure.getMessage(), cause.getMessage())) {
            this.append(buffer, cause.getMessage());
        }
    }
    return this.wrap(failure, LocaleFactory.localizedString("Error", "Error"), buffer);
}

From source file:com.haulmont.cuba.web.gui.WebTimer.java

public WebTimer() {
    component = new Label();
    timerImpl = new CubaTimer();
    timerImpl.setExceptionHandler(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",
                            timerImpl.getLoggingTimerId());
                    stop();//  w  w  w.  j  a  va2  s  . c o  m
                    break;
                }
            }
        } else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) {
            log.warn("NoUserSessionException in timer {}, timer will be stopped",
                    timerImpl.getLoggingTimerId());
            stop();
        }

        throw new RuntimeException("Exception in timer", e);
    });
}

From source file:ch.cyberduck.core.DefaultIOExceptionMappingService.java

@Override
public BackgroundException map(final IOException failure) {
    final Throwable[] stack = ExceptionUtils.getThrowables(failure);
    for (Throwable t : stack) {
        if (t instanceof BackgroundException) {
            return (BackgroundException) t;
        }/*from   w ww .ja va  2 s .  com*/
    }
    if (failure instanceof SSLException) {
        return new SSLExceptionMappingService().map((SSLException) failure);
    }
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (!StringUtils.contains(failure.getMessage(), cause.getMessage())) {
            this.append(buffer, cause.getMessage());
        }
    }
    return this.wrap(failure, buffer);
}

From source file:ch.cyberduck.core.sds.SDSExceptionMappingService.java

@Override
public BackgroundException map(final ApiException failure) {
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SocketException) {
            // Map Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }/* www.j  a v  a2 s. c o m*/
        if (cause instanceof HttpResponseException) {
            return new HttpResponseExceptionMappingService().map((HttpResponseException) cause);
        }
        if (cause instanceof IOException) {
            return new DefaultIOExceptionMappingService().map((IOException) cause);
        }
    }
    final StringBuilder buffer = new StringBuilder();
    if (null != failure.getResponseBody()) {
        final JsonParser parser = new JsonParser();
        try {
            final JsonObject json = parser.parse(new StringReader(failure.getResponseBody())).getAsJsonObject();
            if (json.has("errorCode")) {
                if (json.get("errorCode").isJsonPrimitive()) {
                    final int errorCode = json.getAsJsonPrimitive("errorCode").getAsInt();
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Failure with errorCode %s", errorCode));
                    }
                    final String key = String.format("Error %d", errorCode);
                    final String localized = LocaleFactory.get().localize(key, "SDS");
                    this.append(buffer, localized);
                    if (StringUtils.equals(localized, key)) {
                        log.warn(String.format("Missing user message for error code %d", errorCode));
                        if (json.has("debugInfo")) {
                            if (json.get("debugInfo").isJsonPrimitive()) {
                                this.append(buffer, json.getAsJsonPrimitive("debugInfo").getAsString());
                            }
                        }
                    }
                    switch (failure.getCode()) {
                    case HttpStatus.SC_NOT_FOUND:
                        switch (errorCode) {
                        case -70501:
                            // [-70501] User not found
                            return new AccessDeniedException(buffer.toString(), failure);
                        case -40761:
                            // [-40761] Filekey not found for encrypted file
                            return new AccessDeniedException(buffer.toString(), failure);
                        }
                        break;
                    case HttpStatus.SC_PRECONDITION_FAILED:
                        switch (errorCode) {
                        case -10108:
                            // [-10108] Radius Access-Challenge required.
                            if (json.has("replyMessage")) {
                                if (json.get("replyMessage").isJsonPrimitive()) {
                                    final JsonPrimitive replyMessage = json.getAsJsonPrimitive("replyMessage");
                                    if (log.isDebugEnabled()) {
                                        log.debug(String.format("Failure with replyMessage %s", replyMessage));
                                    }
                                    buffer.append(replyMessage.getAsString());
                                }
                            }
                            return new PartialLoginFailureException(buffer.toString(), failure);
                        }
                        break;
                    case HttpStatus.SC_UNAUTHORIZED:
                        switch (errorCode) {
                        case -10012:
                            // [-10012] Wrong token.
                            return new ExpiredTokenException(buffer.toString(), failure);
                        }
                        break;
                    }
                }
            } else {
                switch (failure.getCode()) {
                case HttpStatus.SC_INTERNAL_SERVER_ERROR:
                    break;
                default:
                    if (json.has("debugInfo")) {
                        log.warn(String.format("Missing error code for failure %s", json));
                        if (json.get("debugInfo").isJsonPrimitive()) {
                            this.append(buffer, json.getAsJsonPrimitive("debugInfo").getAsString());
                        }
                    }
                }
            }
        } catch (JsonParseException e) {
            // Ignore
            this.append(buffer, failure.getMessage());
        }
    }
    switch (failure.getCode()) {
    case HttpStatus.SC_PRECONDITION_FAILED:
        // [-10103] EULA must be accepted
        // [-10104] Password must be changed
        // [-10106] Username must be changed
        return new LoginFailureException(buffer.toString(), failure);
    }
    return new HttpResponseExceptionMappingService().map(failure, buffer, failure.getCode());
}

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

@Override
public Type determine(final BackgroundException failure) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Determine cause for failure %s", failure));
    }//  w  w  w. j ava  2  s.  co m
    if (failure instanceof ConnectionTimeoutException) {
        return Type.network;
    }
    if (failure instanceof ConnectionRefusedException) {
        return Type.network;
    }
    if (failure instanceof ResolveFailedException) {
        return Type.network;
    }
    if (failure instanceof SSLNegotiateException) {
        return Type.application;
    }
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SSLException) {
            return Type.network;
        }
        if (cause instanceof NoHttpResponseException) {
            return Type.network;
        }
        if (cause instanceof ConnectTimeoutException) {
            return Type.network;
        }
        if (cause instanceof SocketException || cause instanceof TimeoutException // Used in Promise#retrieve
                || cause instanceof SocketTimeoutException || cause instanceof UnknownHostException) {
            return Type.network;
        }
    }
    return Type.application;
}

From source file:ch.cyberduck.core.ssl.SSLExceptionMappingService.java

/**
 * close_notify(0),//  ww w. j a v  a  2  s  . com
 * unexpected_message(10),
 * bad_record_mac(20),
 * decryption_failed_RESERVED(21),
 * record_overflow(22),
 * decompression_failure(30),
 * handshake_failure(40),
 * no_certificate_RESERVED(41),
 * bad_certificate(42),
 * unsupported_certificate(43),
 * certificate_revoked(44),
 * certificate_expired(45),
 * certificate_unknown(46),
 * illegal_parameter(47),
 * unknown_ca(48),
 * access_denied(49),
 * decode_error(50),
 * decrypt_error(51),
 * export_restriction_RESERVED(60),
 * protocol_version(70),
 * insufficient_security(71),
 * internal_error(80),
 * user_canceled(90),
 * no_renegotiation(100),
 * unsupported_extension(110),
 */
@Override
public BackgroundException map(final SSLException failure) {
    final StringBuilder buffer = new StringBuilder();
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SocketException) {
            // Map Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
    }
    final String message = failure.getMessage();
    for (Alert alert : Alert.values()) {
        if (StringUtils.contains(message, alert.name())) {
            this.append(buffer, alert.getDescription());
            break;
        }
    }
    if (failure instanceof SSLHandshakeException) {
        if (ExceptionUtils.getRootCause(failure) instanceof CertificateException) {
            log.warn(String.format("Ignore certificate failure %s and drop connection", failure.getMessage()));
            // Server certificate not accepted
            return new ConnectionCanceledException(failure);
        }
        return new SSLNegotiateException(buffer.toString(), failure);
    }
    if (ExceptionUtils.getRootCause(failure) instanceof GeneralSecurityException) {
        this.append(buffer, ExceptionUtils.getRootCause(failure).getMessage());
        return new InteroperabilityException(buffer.toString(), failure);
    }
    this.append(buffer, message);
    return new InteroperabilityException(buffer.toString(), failure);
}

From source file:ch.cyberduck.core.AbstractExceptionMappingService.java

protected BackgroundException wrap(final T failure, final String title, final StringBuilder buffer) {
    if (buffer.toString().isEmpty()) {
        log.warn(String.format("No message for failure %s", failure));
        this.append(buffer, LocaleFactory.localizedString("Interoperability failure", "Error"));
    }//from  w w w .  j  a va2s. com
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof InterruptedIOException) {
            // Handling socket timeouts
            return new ConnectionTimeoutException(buffer.toString(), failure);
        }
        if (cause instanceof TimeoutException) {
            //
            return new ConnectionTimeoutException(buffer.toString(), failure);
        }
        if (cause instanceof SocketException) {
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
        if (cause instanceof EOFException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
        if (cause instanceof UnknownHostException) {
            return new ResolveFailedException(buffer.toString(), failure);
        }
        if (cause instanceof NoHttpResponseException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
    }
    return new BackgroundException(title, buffer.toString(), failure);
}

From source file:com.qwazr.server.ServerException.java

public static ServerException of(String message, final Throwable throwable) {
    if (throwable instanceof ServerException)
        return (ServerException) throwable;

    int status = 500;

    final int serverExceptionPos = ExceptionUtils.indexOfType(throwable, ServerException.class);
    if (serverExceptionPos != -1)
        return (ServerException) ExceptionUtils.getThrowableList(throwable).get(serverExceptionPos);

    final int webApplicationExceptionPos = ExceptionUtils.indexOfType(throwable, WebApplicationException.class);
    if (webApplicationExceptionPos != -1)
        status = ((WebApplicationException) ExceptionUtils.getThrowableList(throwable)
                .get(webApplicationExceptionPos)).getResponse().getStatus();

    if (StringUtils.isBlank(message)) {
        message = throwable.getMessage();
        if (StringUtils.isBlank(message))
            message = ExceptionUtils.getRootCauseMessage(throwable);
        if (StringUtils.isBlank(message))
            message = "Internal server error";
    }//  www . ja  v a  2  s. c  o m

    return new ServerException(status, message, throwable);
}

From source file:de.pixida.logtest.engine.Automaton.java

public Automaton(final IAutomatonDefinition aAutomatonDefinition, final Map<String, String> aParameters) {
    LOG.debug("Creating automaton with definition '{}' and parameters '{}'", aAutomatonDefinition, aParameters);
    Validate.notNull(aAutomatonDefinition);
    Validate.notNull(aParameters);//from ww  w .  j ava2 s  .c o  m
    this.automatonDefinition = aAutomatonDefinition;
    this.parameters = new AutomatonParameters(aParameters);
    try {
        this.loadAutomatonFromDefinition();
        if (this.description != null) {
            this.description = this.parameters.insertAllParameters(this.description);
        }
        LOG.debug("Automaton description: {}", this.description);
        this.checkAutomatonAndFindInitialNode();
        this.compileScripts();
    } catch (final InvalidAutomatonDefinitionException iade) {
        final String errorsWithoutStackTraces = ExceptionUtils.getThrowableList(iade).stream()
                .map(e -> e.getMessage()).collect(Collectors.joining("; "));
        LOG.error("Error while initializing automaton '{}': {}", this.automatonDefinition,
                errorsWithoutStackTraces);
        this.thrownException = iade;
    } catch (final RuntimeException re) {
        this.thrownException = re;
        throw re;
    }
}

From source file:org.apache.syncope.core.misc.ExceptionUtil.java

/**
 * Uses commons lang's ExceptionUtils to provide a representation of the full stack trace of the given throwable.
 *
 * @param t throwable to build stack trace from
 * @return a string representation of full stack trace of the given throwable
 *///from w ww .j a v  a  2 s  .  c o m
public static String getFullStackTrace(final Throwable t) {
    StringBuilder result = new StringBuilder();

    for (Throwable throwable : ExceptionUtils.getThrowableList(t)) {
        result.append(ExceptionUtils.getMessage(throwable)).append('\n')
                .append(ExceptionUtils.getStackTrace(throwable)).append("\n\n");
    }

    return result.toString();
}