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

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

Introduction

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

Prototype

public static List 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:com.jaspersoft.jasperserver.war.util.JSExceptionUtils.java

@SuppressWarnings("unchecked")
public static <E extends Throwable> E extractCause(Throwable exception, Class<E> exceptionType) {
    int index = ExceptionUtils.indexOfThrowable(exception, exceptionType);
    E e;/*from  ww  w . jav  a2 s .  co m*/
    if (index >= 0) {
        e = (E) ExceptionUtils.getThrowableList(exception).get(index);
    } else {
        e = null;
    }
    return e;
}

From source file:com.haulmont.cuba.desktop.exception.ConnectExceptionHandler.java

@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);
            }//from ww w  .j a v  a  2  s  . c om
            return true;
        }
    }
    return false;
}

From source file:com.haulmont.cuba.gui.exception.MssqlDateOutOfRangeExceptionHandler.java

@Override
@SuppressWarnings("unchecked")
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);/*from  ww  w .j a v  a  2s  .  c om*/
            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;
}

From source file:com.haulmont.cuba.gui.exception.AbstractGenericExceptionHandler.java

@Override
public boolean handle(Throwable exception, WindowManager windowManager) {
    //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(throwable.getClass().getName(), throwable.getMessage(), throwable, windowManager);
            return true;
        }//from w w w  .  j a  v  a  2 s . c om
        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;
}

From source file:com.haulmont.cuba.desktop.exception.AbstractExceptionHandler.java

@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;
        }//  ww  w  .  j av  a 2 s . c  o m
        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;
}

From source file:com.haulmont.cuba.web.exception.AbstractExceptionHandler.java

@Override
public boolean handle(ErrorEvent event, App app) {
    Throwable exception = event.getThrowable();
    //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(app, throwable.getClass().getName(), throwable.getMessage(), throwable);
            return true;
        }/*w  w w.j  ava 2s .  c  o  m*/
        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;
}

From source file:com.haulmont.cuba.core.global.RemoteException.java

@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;/*  www  .j  a v a 2  s .c o  m*/
                break;
            }
        }
        if (suitable)
            causes.add(new Cause(t));
        else
            causes.add(new Cause(t.getClass().getName(), t.getMessage()));
    }
}

From source file:com.haulmont.cuba.client.sys.MessagesClientImpl.java

@Override
protected String searchRemotely(String pack, String key, Locale locale) {
    if (!remoteSearch || !AppContext.isStarted())
        return null;

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

    StopWatch stopWatch = new Slf4JStopWatch("Messages.searchRemotely");
    try {/*w  w w. jav  a 2 s  .  co  m*/
        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();
    }
}

From source file:fr.xebia.cxf.interceptor.FaultEnhancerInterceptor.java

@Override
public void handleFault(Message message) {
    Exchange exchange = message.getExchange();
    if (exchange == null) {
        // do nothing
    } else {/*from   w  w  w. j a va  2  s .  c o m*/
        Fault fault = (Fault) message.getContent(Exception.class);
        FaultMode mode = message.get(FaultMode.class);

        String msg = "Exception invoking service " + exchange.get(Message.WSDL_INTERFACE);
        if (exchange.get(OperationInfo.class) != null) {
            msg += ", operation=" + exchange.get(OperationInfo.class).getName();
        }
        if (exchange.get(Message.ENDPOINT_ADDRESS) != null) {
            msg += ", url=" + exchange.get(Message.ENDPOINT_ADDRESS);
        }
        Throwable cause = fault.getCause() == null ? fault : fault.getCause();

        Fault enhancedFault;
        Level level;
        if (FaultMode.UNCHECKED_APPLICATION_FAULT.equals(mode) || FaultMode.LOGICAL_RUNTIME_FAULT.equals(mode)
                || FaultMode.RUNTIME_FAULT.equals(mode)) {
            level = Level.ERROR;
            enhancedFault = new Fault(new RuntimeException(msg, cause));
        } else if (FaultMode.CHECKED_APPLICATION_FAULT.equals(mode)) {
            enhancedFault = fault;
            level = Level.INFO;
        } else /* mode == null */ {
            enhancedFault = new Fault(new RuntimeException(msg, cause));
            level = Level.INFO;
        }
        if (logger.isDebugEnabled()) {
            logger.log(level, msg, cause);
        } else {
            List<Throwable> throwables = ExceptionUtils.getThrowableList(cause);
            StringBuilder msgBuilder = new StringBuilder(msg);
            for (Throwable throwable : throwables) {
                msgBuilder.append(" " + throwable);
            }
            logger.log(level, msgBuilder.toString());
        }

        message.setContent(Exception.class, enhancedFault);
        if (exchange.get(Exception.class) != null) {
            exchange.put(Exception.class, enhancedFault);
        }
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimer.java

protected void handleTimerException(RuntimeException ex) {
    if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) {
        // If a ConnectException occurred, just log it and ignore
        log.warn("onTimer error: " + ex.getMessage());
    } else {//from   www .j a va  2s  .  c  o  m
        // Otherwise throw the exception, but first search for NoUserSessionException in chain,
        // if found - stop the timer
        int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class);
        if (reIdx > -1) {
            RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx);
            for (RemoteException.Cause cause : re.getCauses()) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (cause.getThrowable() instanceof NoUserSessionException) {
                    log.warn("NoUserSessionException in timer, timer will be stopped");
                    disposeTimer();
                    break;
                }
            }
        } else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) {
            log.warn("NoUserSessionException in timer, timer will be stopped");
            disposeTimer();
        }

        throw ex;
    }
}