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:com.payu.ratel.proxy.RetryPolicyInvocationHandler.java

@SuppressWarnings("PMD.AvoidCatchingThrowable")
public Object invokeWithRetry(MethodInvocation methodInvocation, int count) throws Throwable {
    MethodInvocation methodInvocationCopy = ((ProxyMethodInvocation) methodInvocation).invocableClone();
    try {/*from w  w w . j  av a 2s  . c  om*/
        return methodInvocationCopy.proceed();
    } catch (Throwable thrownException) {
        LOGGER.warn("Ratel - Retry Policy was triggered for service {} cause: {} ", methodInvocation.getThis(),
                thrownException.getCause());
        if (isInStacktrace(thrownException, config.getRetryOnException()) && count < config.getRetryCount()) {
            Thread.sleep(config.getWaitingTime());

            return invokeWithRetry(methodInvocation, count + 1);
        }

        throw thrownException;
    }
}

From source file:br.com.gerenciapessoal.util.jsf.JsfExceptionHandler.java

@SuppressWarnings("ThrowableResultIgnored")
private NegocioException getNegocioException(Throwable exception) {
    if (exception instanceof NegocioException) {
        return (NegocioException) exception;
    } else if (exception.getCause() != null) {
        return getNegocioException(exception.getCause());
    }//  w w w  .  j a  v  a 2s. com

    return null;
}

From source file:com.surevine.alfresco.webscript.mis.ListFoldersWithExplicitDeletePermissionsWebscript.java

protected void operateOn(NodeRef nodeRef) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Operating on %s", nodeRef));
    }/*ww w .j  a v  a 2 s.c  o m*/
    Action action = _actionService.createAction(FixFolderPermissionsAction.NAME);
    try {
        AuthenticationUtil.runAs(new ExecuteJobWork(action, nodeRef, _actionService),
                AuthenticationUtil.getSystemUserName());
    } catch (Throwable e) {
        if (e.getCause() != null) {
            e = e.getCause();
        }
        LOG.warn("Could not fix permissions of " + nodeRef + " due to: " + e, e);
    }
}

From source file:org.openmrs.web.controller.report.ReportSchemaXmlFormController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 *///w  w  w . ja va2s .c  om
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandObject,
        BindException errors) throws Exception {
    ReportSchemaXml reportSchemaXml = (ReportSchemaXml) commandObject;
    ReportService reportService = (ReportService) Context.getService(ReportService.class);

    try {
        // create a new object out of their xml in order to verify xml and copy out the id/name/desc
        ReportSchema schema = reportService.getReportSchema(reportSchemaXml);

        // if the user changed the reportSchemaId to create a new one, create a new object here 
        // so hibernate doesn't complain
        if (reportSchemaXml.getReportSchemaId() != null
                && !schema.getReportSchemaId().equals(reportSchemaXml.getReportSchemaId())) {
            String xml = reportSchemaXml.getXml();
            reportSchemaXml = new ReportSchemaXml();
            reportSchemaXml.setXml(xml);
        }

        reportSchemaXml.populateFromReportSchema(schema);

        // save the xml to the database
        reportService.saveReportSchemaXml(reportSchemaXml);

    } catch (Exception ex) {
        log.warn("Exception building ReportSchema from XML", ex);
        if (ex.getCause() != null) {
            Throwable temp = ex.getCause();
            while (temp.getCause() != null)
                temp = temp.getCause();
            errors.rejectValue("xml", temp.getMessage());
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append("Invalid XML content<br/>");
            sb.append(ex).append("<br/>");
            for (StackTraceElement e : ex.getStackTrace())
                sb.append(e.toString()).append("<br/>");
            errors.rejectValue("xml", sb.toString());
        }
        return showForm(request, response, errors);
    }

    HttpSession httpSession = request.getSession();
    httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "reportingcompatibility.Report.manageSchema.saved");
    return new ModelAndView(new RedirectView(getSuccessView()));
}

From source file:com.tesora.dve.mysqlapi.repl.MyReplErrorAdjudicator.java

private Throwable getRootException(Throwable exception) {
    Throwable root, lastEx = exception;
    for (root = exception; (root = root.getCause()) != null;) {
        lastEx = root;//from w w w  .ja  v a 2 s .  c o  m
    }
    return lastEx;
}

From source file:net.solarnetwork.node.control.modbus.heartbeat.ModbusHeartbeatJob.java

@Override
protected void executeInternal(JobExecutionContext jobContext) throws Exception {
    final DateTime heartbeatDate = new DateTime();
    String heartbeatMessage = null;
    boolean heartbeatSuccess = false;
    try {// w  ww . java2 s  . co  m
        final Boolean executed = setValue(registerValue);
        if (executed == null) {
            // hmm, how can this be localized?
            heartbeatMessage = "No Modbus connection available.";
        } else if (executed.booleanValue() == false) {
            heartbeatMessage = "Unknown Modbus error.";
        } else {
            // good
            heartbeatSuccess = true;
        }
    } catch (RuntimeException e) {
        log.error("Error sending heartbeat message: {}", e.toString());
        Throwable root = e;
        while (root.getCause() != null) {
            root = root.getCause();
        }
        heartbeatMessage = "Error: " + root.getMessage();
    }
    STATUS_MAP.put(getStatusKey(), new JobStatus(heartbeatDate, heartbeatSuccess, heartbeatMessage));
}

From source file:com.wealdtech.jersey.providers.HttpExceptionMapper.java

private String statusToJSON(final HttpException exception) {
    WealdError err = exception;//from   w  ww.  j a  v a  2 s .com
    Throwable t = exception.getCause();
    while (t != null) {
        if (t instanceof WealdError) {
            err = (WealdError) t;
        }
        t = t.getCause();
    }
    ErrorInfo errorInfo = new ErrorInfo(null, err.getUserMessage(), err.getMessage(), err.getUrl());

    try {
        return MAPPER.writeValueAsString(errorInfo);
    } catch (JsonProcessingException e) {
        LOGGER.error("Failed to generate JSON for status \"{}\"", errorInfo);
        return "{\"message\":\"An error occurred\"}";
    }
}

From source file:io.coala.enterprise.Fact.java

/**
 * @param subtype the type of {@link Fact} to mimic
 * @param callObserver an {@link Observer} of method call, or {@code null}
 * @return the {@link Proxy} instance//from  w w w .  j a  v a  2 s  .c o  m
 */
@SuppressWarnings("unchecked")
static <F extends Fact> F proxyAs(final Fact impl, final Class<F> subtype,
        final Observer<Method> callObserver) {
    final F proxy = (F) Proxy.newProxyInstance(subtype.getClassLoader(), new Class<?>[] { subtype },
            (self, method, args) -> {
                try {
                    final Object result = method.isDefault() && Proxy.isProxyClass(self.getClass())
                            ? ReflectUtil.invokeDefaultMethod(self, method, args)
                            : method.invoke(impl, args);
                    if (callObserver != null)
                        callObserver.onNext(method);
                    return result;
                } catch (Throwable e) {
                    if (e instanceof IllegalArgumentException)
                        try {
                            return ReflectUtil.invokeAsBean(impl.properties(), subtype, method, args);
                        } catch (final Exception ignore) {
                            LogUtil.getLogger(Fact.class).warn("{}method call failed: {}",
                                    method.isDefault() ? "default " : "", method, ignore);
                        }
                    if (e instanceof InvocationTargetException)
                        e = e.getCause();
                    if (callObserver != null)
                        callObserver.onError(e);
                    throw e;
                }
            });
    return proxy;
}

From source file:net.geoprism.SessionFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq = (HttpServletRequest) req;
    HttpServletResponse httpRes = (HttpServletResponse) res;

    // response time logging
    req.setAttribute("startTime", (Long) (new Date().getTime()));

    HttpSession session = httpReq.getSession();

    WebClientSession clientSession = (WebClientSession) session.getAttribute(ClientConstants.CLIENTSESSION);

    // This isLoggedIn check is not 100% sufficient, it doesn't go to the server
    // and check, it only does it locally, so if the session has expired it'l
    // let it through.
    if (clientSession != null && clientSession.getRequest().isLoggedIn()) {
        try {/*from ww w.j  av  a 2  s .  co m*/
            req.setAttribute(ClientConstants.CLIENTREQUEST, clientSession.getRequest());
            chain.doFilter(req, res);
        } catch (Throwable t) {
            while (t.getCause() != null && !t.getCause().equals(t)) {
                t = t.getCause();
            }

            if (t instanceof InvalidSessionExceptionDTO) {
                // If we're asynchronous, we want to return a serialized exception
                if (StringUtils.endsWith(httpReq.getRequestURL().toString(), ".mojax")) {
                    ErrorUtility.prepareAjaxThrowable(t, httpRes);
                } else {
                    // Not an asynchronous request, redirect to the login page.
                    httpRes.sendRedirect(httpReq.getContextPath() + "/loginRedirect");
                }
            } else {
                if (t instanceof RuntimeException) {
                    throw (RuntimeException) t;
                } else {
                    throw new RuntimeException(t);
                }
            }
        }

        return;
    } else if (pathAllowed(httpReq)) {
        chain.doFilter(req, res);
        return;
    } else {
        // The user is not logged in

        // If we're asynchronous, we want to return a serialized exception
        if (StringUtils.endsWith(httpReq.getRequestURL().toString(), ".mojax")) {
            ErrorUtility.prepareAjaxThrowable(new InvalidSessionExceptionDTO(), httpRes);
        } else {
            // Not an asynchronous request, redirect to the login page.
            httpRes.sendRedirect(httpReq.getContextPath() + "/loginRedirect");
        }
    }
}

From source file:jp.primecloud.auto.ui.ComponentsErrorHandler.java

@Override
public boolean handleComponentError(ComponentErrorEvent event) {
    // ?/* w ww.  j ava 2  s .c  o m*/
    Throwable throwable = event.getThrowable();
    if (throwable instanceof ListenerMethod.MethodException) {
        throwable = throwable.getCause();
    }

    // ??????
    if (!(throwable instanceof AutoException) && !(throwable instanceof MultiCauseException)) {
        String message = "[ECOMMON-000000] " + MessageUtils.getMessage("ECOMMON-000000");
        log.error(message, throwable);
    }

    String message;
    if (throwable instanceof AutoApplicationException) {
        // ?
        AutoApplicationException e = (AutoApplicationException) throwable;
        message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
    } else {
        // ?????
        String code;
        if (throwable instanceof AutoException) {
            code = ((AutoException) throwable).getCode();
        } else {
            code = "ECOMMON-000000";
        }
        message = ViewMessages.getMessage("EUI-000001", code);
    }
    String caption = ViewProperties.getCaption("dialog.error");

    DialogConfirm dialog = new DialogConfirm(caption, message, Buttons.OK);
    mainWindow.addWindow(dialog);

    return true;
}