Java Code Examples for org.apache.commons.lang3.exception.ExceptionUtils#getThrowableList()

The following examples show how to use org.apache.commons.lang3.exception.ExceptionUtils#getThrowableList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoregateExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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);
        }
        if(cause instanceof HttpResponseException) {
            return new DefaultHttpResponseExceptionMappingService().map((HttpResponseException) cause);
        }
        if(cause instanceof IOException) {
            return new DefaultIOExceptionMappingService().map((IOException) cause);
        }
        if(cause instanceof IllegalStateException) {
            // Caused by: ch.cyberduck.core.sds.io.swagger.client.ApiException: javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Connection pool shut down
            return new ConnectionCanceledException(cause);
        }
    }
    return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(failure.getCode(), failure.getMessage()));
}
 
Example 2
Source File: MssqlDateOutOfRangeExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(Throwable exception, WindowManager windowManager) {
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (className.contains(throwable.getClass().getName()) && isDateOutOfRangeMessage(throwable.getMessage())) {
            doHandle(windowManager);
            return true;
        }
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (className.contains(cause.getClassName()) && isDateOutOfRangeMessage(throwable.getMessage())) {
                    doHandle(windowManager);
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: AbstractUiExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(Throwable exception, UiContext context) {
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, context);
            return true;
        }
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
                    doHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable(), context);
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: AbstractGenericExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(Throwable exception, WindowManager windowManager) {
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, windowManager);
            return true;
        }
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
                    doHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable(), windowManager);
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 5
Source File: DefaultIOExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BackgroundException map(final IOException failure) {
    final Throwable[] stack = ExceptionUtils.getThrowables(failure);
    for(Throwable t : stack) {
        if(t instanceof BackgroundException) {
            return (BackgroundException) t;
        }
    }
    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);
}
 
Example 6
Source File: ConnectExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(Thread thread, Throwable exception) {
    @SuppressWarnings("unchecked")
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (throwable instanceof RemoteAccessException) {
            Messages messages = AppBeans.get(Messages.NAME);
            String msg = messages.getMessage(getClass(), "connectException.message");
            if (throwable.getCause() == null) {
                App.getInstance().getMainFrame().showNotification(msg, Frame.NotificationType.ERROR);
            } else {
                String description = messages.formatMessage(getClass(), "connectException.description",
                        throwable.getCause().toString());
                App.getInstance().getMainFrame().showNotification(msg, description, Frame.NotificationType.ERROR);
            }
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: AbstractExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(ErrorEvent event, App app) {
    Throwable exception = event.getThrowable();
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(app, throwable.getClass().getName(), throwable.getMessage(), throwable);
            return true;
        }
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
                    doHandle(app, cause.getClassName(), cause.getMessage(), cause.getThrowable());
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 8
Source File: RemoteException.java    From cuba with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public RemoteException(Throwable throwable) {
    List<Throwable> list = ExceptionUtils.getThrowableList(throwable);
    for (int i = 0; i < list.size(); i++) {
        Throwable t = list.get(i);
        boolean suitable = true;
        List<Throwable> causesOfT = list.subList(i, list.size());
        for (Throwable aCauseOfT : causesOfT) {
            if (!isSuitable(aCauseOfT)) {
                suitable = false;
                break;
            }
        }
        if (suitable)
            causes.add(new Cause(t));
        else
            causes.add(new Cause(t.getClass().getName(), t.getMessage()));
    }
}
 
Example 9
Source File: AbstractExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(Thread thread, Throwable exception) {
    //noinspection unchecked
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (classNames.contains(throwable.getClass().getName())
                && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
            doHandle(thread, throwable.getClass().getName(), throwable.getMessage(), throwable);
            return true;
        }
        if (throwable instanceof RemoteException) {
            RemoteException remoteException = (RemoteException) throwable;
            for (RemoteException.Cause cause : remoteException.getCauses()) {
                if (classNames.contains(cause.getClassName())
                        && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
                    doHandle(thread, cause.getClassName(), cause.getMessage(), cause.getThrowable());
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 10
Source File: NetworkErrorHandler.java    From android-atleap with Apache License 2.0 5 votes vote down vote up
@Override
public Throwable handleError(RetrofitError retrofitError) {
    if (retrofitError.isNetworkError()) {
        Log.w(TAG, "Cannot connect to " + retrofitError.getUrl());
        return new NoNetworkException();
    }


    Response response = retrofitError.getResponse();
    if (response != null) {
        int status = response.getStatus();
        if (status == 401) {
            //throw our own exception about unauthorized access
            Log.w(TAG, "Access in not authorized " + retrofitError.getUrl());
            Context context = AppContext.getContext();
            AuthHelper.reCreateAuthTokenForLastAccountBlocking(context, Constants.ACCOUNT_TYPE, Constants.ACCOUNT_TOKEN_TYPE, null, null, null);
            return new UnauthorizedException("Access in not authorized " + retrofitError.getUrl(), retrofitError);
        } else if (status >= 300) {
            Log.w(TAG, "Error " + String.valueOf(status) + " while accessing " + retrofitError.getUrl());
            return retrofitError;
        }
    }

    int index = ExceptionUtils.indexOfType(retrofitError, ServerErrorException.class);

    if (index >= 0) {
        List<Throwable> errorList = ExceptionUtils.getThrowableList(retrofitError);
        ServerErrorException serverErrorException = (ServerErrorException)errorList.get(index);
        if (serverErrorException instanceof DeveloperErrorException) {
            Log.e(TAG, "Developer error with code" + serverErrorException.getErrorCode(), serverErrorException);
        }
        return serverErrorException;
    }

    return retrofitError;
}
 
Example 11
Source File: ResponseExceptionHandler.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Method for handling exception of type {@link MultipartException} which is
 * thrown in case the request body is not well formed and cannot be
 * deserialized. Called by the Spring-Framework for exception handling.
 *
 * @param request
 *            the Http request
 * @param ex
 *            the exception which occurred
 * @return the entity to be responded containing the exception information
 *         as entity.
 */
@ExceptionHandler(MultipartException.class)
public ResponseEntity<ExceptionInfo> handleMultipartException(final HttpServletRequest request,
        final Exception ex) {

    logRequest(request, ex);

    final List<Throwable> throwables = ExceptionUtils.getThrowableList(ex);
    final Throwable responseCause = Iterables.getLast(throwables);

    if (responseCause.getMessage().isEmpty()) {
        LOG.warn("Request {} lead to MultipartException without root cause message:\n{}", request.getRequestURL(),
                ex.getStackTrace());
    }

    final ExceptionInfo response = createExceptionInfo(new MultiPartFileUploadException(responseCause));
    return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
 
Example 12
Source File: MessagesClientImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
protected String searchRemotely(String pack, String key, Locale locale) {
    if (!remoteSearch || !AppContext.isStarted())
        return null;

    if (log.isTraceEnabled())
        log.trace("searchRemotely: " + pack + "/" +  LocaleResolver.localeToString(locale) + "/" + key);

    StopWatch stopWatch = new Slf4JStopWatch("Messages.searchRemotely");
    try {
        String message = localizedMessageService.getMessage(pack, key, locale);
        if (key.equals(message))
            return null;
        else
            return message;
    } catch (Exception e) {
        List list = ExceptionUtils.getThrowableList(e);
        for (Object throwable : list) {
            if (throwable instanceof SocketException) {
                log.trace("searchRemotely: {}", throwable);
                return null; // silently ignore network errors
            }
        }
        throw (RuntimeException) e;
    } finally {
        stopWatch.stop();
    }
}
 
Example 13
Source File: AppUI.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected String getExceptionCauseMessage(Exception exception) {
    for (Throwable throwable : ExceptionUtils.getThrowableList(exception)) {
        if (throwable instanceof RemoteAccessException) {
            return throwable.toString() +
                    "\n\nDue to this error, 'web' block cannot connect to the remote 'core' block.\n" +
                    "First, check the 'core' server log for exceptions to ensure it has started properly.\n" +
                    "If there are no exceptions in the 'core' log, check that 'cuba.connectionUrlList' property value " +
                    "contains the valid address of the 'core' server and ends with the web context name of the 'core' block, " +
                    "e.g. 'cuba.connectionUrlList = http://somehost:8080/app-core'";
        } else if (throwable instanceof LocalServiceAccessException) {
            return throwable.getMessage();
        }
    }
    return ExceptionUtils.getRootCauseMessage(exception);
}
 
Example 14
Source File: DefaultExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BackgroundException map(final Throwable failure) {
    final StringBuilder buffer = new StringBuilder();
    if(failure instanceof RuntimeException) {
        this.append(buffer, LocaleFactory.localizedString("Unknown application error"));
    }
    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);
}
 
Example 15
Source File: SSLExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
/**
 * close_notify(0),
 * 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) {
            // 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.containsIgnoreCase(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);
        }
        if(ExceptionUtils.getRootCause(failure) instanceof EOFException) {
            // SSL peer shut down incorrectly
            return this.wrap(failure, buffer);
        }
        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);
}
 
Example 16
Source File: AbstractExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
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("Unknown"));
    }
    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);
        }
        if(cause instanceof ConnectionClosedException) {
            return new ConnectionRefusedException(buffer.toString(), failure);
        }
        if(cause instanceof InterruptedException) {
            return new ConnectionCanceledException(buffer.toString(), failure);
        }
    }
    if(failure instanceof RuntimeException) {
        return new ConnectionCanceledException(title, buffer.toString(), failure);
    }
    return new BackgroundException(title, buffer.toString(), failure);
}
 
Example 17
Source File: AzureExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BackgroundException map(final StorageException failure) {
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    if(ExceptionUtils.getRootCause(failure) instanceof UnknownHostException) {
        return new NotfoundException(buffer.toString(), failure);
    }
    switch(failure.getHttpStatusCode()) {
        case 403:
            return new LoginFailureException(buffer.toString(), failure);
        case 404:
            return new NotfoundException(buffer.toString(), failure);
        case 304:
        case 405:
        case 400:
        case 411:
        case 412:
            return new InteroperabilityException(buffer.toString(), failure);
        case 500:
            // InternalError
            // OperationTimedOut
            return new ConnectionTimeoutException(buffer.toString(), failure);
        case 503:
            // ServerBusy
            return new RetriableAccessDeniedException(buffer.toString(), failure);
    }
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(cause instanceof SSLException) {
            return new SSLExceptionMappingService().map(buffer.toString(), (SSLException) cause);
        }
    }
    return this.wrap(failure, buffer);
}
 
Example 18
Source File: DefaultFailureDiagnostics.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Type determine(final BackgroundException failure) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Determine cause for failure %s", failure));
    }
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(failure instanceof UnsupportedException) {
            return Type.unsupported;
        }
        if(failure instanceof LoginFailureException) {
            return Type.login;
        }
        if(cause instanceof ResolveFailedException) {
            return Type.network;
        }
        if(failure instanceof ConnectionCanceledException) {
            return Type.cancel;
        }
        if(cause instanceof ConnectionTimeoutException) {
            return Type.network;
        }
        if(cause instanceof ConnectionRefusedException) {
            return Type.network;
        }
        if(cause instanceof SSLNegotiateException) {
            return Type.application;
        }
        if(cause instanceof SSLHandshakeException) {
            return Type.application;
        }
        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 IOResumeException
            || cause instanceof TimeoutException // Used in Promise#retrieve
            || cause instanceof SocketTimeoutException
            || cause instanceof UnknownHostException) {
            return Type.network;
        }
    }
    return Type.application;
}