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:org.openmrs.web.controller.report.ReportSchemaXmlFormController.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 *//*  www . j  av a  2s  .c  om*/
public void validate(Object commandObject, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "xml", "Paste XML for report before saving");
    ReportSchemaXml rsx = (ReportSchemaXml) commandObject;
    try {
        ReportService reportService = (ReportService) Context.getService(ReportService.class);
        ReportSchema schema = reportService.getReportSchema(rsx);
        if (schema == null)
            throw new NullPointerException();
    } 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());
        }
    }
}

From source file:com.opensymphony.able.filter.SimpleTransactionServletFilter.java

public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    // TODO we could get clever and figure out what URIs are read only transactions etc
    final TransactionTemplate transactionTemplate = (TransactionTemplate) context
            .getBean("transactionTemplate");
    transactionTemplate.setReadOnly(false);

    if (log.isDebugEnabled()) {
        log.debug("Starting a transaction");
    }//from  w  w w  .j a  v  a2  s  .  c  o  m

    try {
        Exception e = (Exception) transactionTemplate.execute(new TransactionCallback() {

            public Object doInTransaction(TransactionStatus status) {
                try {
                    TransactionOutcome outcome = new TransactionOutcome(status, transactionTemplate);
                    TransactionOutcome.setTransactionOutcome(outcome);
                    filterChain.doFilter(request, response);

                    if (outcome.isRollbackOnly()) {
                        log.debug("Outcome is rollback");
                        status.setRollbackOnly();
                    }

                    if (log.isDebugEnabled()) {
                        log.debug("Completing a transaction with rollback: " + status.isRollbackOnly());
                    }
                    return null;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    return e;
                }
            }
        });

        if (log.isDebugEnabled()) {
            log.debug("End transaction with exception: " + e);
        }

        if (e instanceof IOException) {
            throw (IOException) e;
        } else if (e instanceof ServletException) {
            throw (ServletException) e;
        } else if (e != null) {
            throw new ServletException(e);
        }
    } catch (TransactionException e) {
        Throwable cause = e.getCause();
        if (cause.getCause() != null) {
            cause = cause.getCause();
        }
        ;
        if (cause instanceof JDBCException) {
            JDBCException jdbcException = (JDBCException) cause;
            SQLException sqlException = jdbcException.getSQLException();
            throw new ServletException("Failed to execute: " + jdbcException.getSQL() + ": error: "
                    + sqlException.getSQLState() + ". Reason: " + sqlException, sqlException);
        }
        throw new ServletException(cause);
    } finally {
        TransactionOutcome.setTransactionOutcome(null);
    }
}

From source file:fr.xebia.management.statistics.ServiceStatistics.java

/**
 * Returns <code>true</code> if the given <code>throwable</code> or one of
 * its cause is an instance of one of the given <code>throwableTypes</code>.
 *//*from  ww  w.j a  v  a 2 s  .  co  m*/
public static boolean containsThrowableOfType(Throwable throwable, Class<?>... throwableTypes) {
    List<Throwable> alreadyProcessedThrowables = new ArrayList<Throwable>();
    while (true) {
        if (throwable == null) {
            // end of the list of causes
            return false;
        } else if (alreadyProcessedThrowables.contains(throwable)) {
            // infinite loop in causes
            return false;
        } else {
            for (Class<?> throwableType : throwableTypes) {
                if (throwableType.isAssignableFrom(throwable.getClass())) {
                    return true;
                }
            }
            alreadyProcessedThrowables.add(throwable);
            throwable = throwable.getCause();
        }
    }
}

From source file:com.nts.alphamale.handler.FollowerHandler.java

/***
 * replay ?? //www . j  a va2  s .c  om
 * @param jobs
 */
@Subscribe
public void task(List<Job> jobs) {
    ExecutionLogManager.clear();
    for (Job job : jobs) {
        Job rjob = null;
        String eMsg = null;
        try {
            rjob = (Job) job.clone();
            if (rjob.getJobType() == JobType.POSITION_BASE) {
                rjob.convertPoint(deviceInfo);
            }
            Object rsltObj = client.invoke(rjob);
            if (rsltObj instanceof Boolean) {
                boolean isSuccess = (Boolean) rsltObj;
                ExecutionLogManager.add(rjob.getSeq(), rjob.getTitle(), serial, deviceInfo.getModel(),
                        isSuccess, "unknown");
            }
        } catch (Throwable e) {
            if (e.getCause() != null) {
                eMsg = e.getCause().getMessage();
            } else {
                eMsg = e.getMessage();
            }
            log.info("Exception Follower(" + deviceInfo.getModel() + ") - " + e.getStackTrace());
            ExecutionLogManager.add(rjob.getSeq(), rjob.getTitle(), serial, deviceInfo.getModel(), false, eMsg);
        } finally {
            ExecutionLogManager.send(rjob.getSeq(), true);
        }
    }
}

From source file:act.view.beetl.BeetlTemplateException.java

@Override
public String errorMessage() {
    if (isNativeException()) {
        Throwable cause = errorInfo.getCause();
        while (null != cause) {
            if (null == cause.getCause()) {
                return cause.getMessage();
            }//  w w  w  . j  av a 2 s. c o  m
            cause = cause.getCause();
        }
        return S.concat(errorInfo.getErrorCode(), ": ", errorInfo.getMsg());
    }
    StringBuilder sb = new StringBuilder(errorInfo.getType());
    String tokenText = errorInfo.getErrorTokenText();
    if (S.notBlank(tokenText)) {
        sb.append(":<b>").append(errorInfo.getErrorTokenText()).append(" </b>");
    }
    String msg = errorInfo.getMsg();
    if (S.notBlank(msg)) {
        sb.append("<br><pre>").append(msg).append("</pre>");
    }

    return sb.toString();
}

From source file:com.payu.ratel.proxy.RetryPolicyInvocationHandler.java

private boolean isInStacktrace(Throwable stackTrace, Class target) {
    Throwable t = stackTrace;
    while (t != null) {
        if (t.getClass().equals(target)) {
            return true;
        }/*from  w w w . jav  a 2 s.  c  o m*/

        t = t.getCause();
    }

    return false;
}

From source file:com.enonic.cms.core.portal.rendering.PortletErrorMessageMarkupCreator.java

private String getDetails(final Exception e) {
    Throwable error = e;
    final StringWriter writer = new StringWriter();

    if (error instanceof PortletXsltViewTransformationException) {
        error = error.getCause();
    }//from   w w w  . j a  v  a2  s .co m

    error.printStackTrace(new PrintWriter(writer));
    return StringEscapeUtils.escapeHtml(writer.toString());
}

From source file:com.evolveum.midpoint.test.IntegrationTestTools.java

public static void assertNotInMessageRecursive(Throwable e, String substring) {
    assert !e.getMessage().contains(substring) : "The substring '" + substring
            + "' was found in the message of exception " + e + ": " + e.getMessage();
    if (e.getCause() != null) {
        assertNotInMessageRecursive(e.getCause(), substring);
    }/*from   w  ww .  ja  va  2 s  .  c  om*/
}

From source file:hoptoad.HoptoadNoticeBuilder.java

private void errorClass(Throwable throwable) {
    Throwable cause = throwable;
    while (cause.getCause() != null) {
        cause = cause.getCause();/*from ww w . j ava  2 s.  c o  m*/
    }
    this.errorClass = cause.getClass().getName();
    if (StringUtils.trimToNull(errorMessage) == null) {
        errorMessage = '[' + throwable.getClass().toString() + ']';
    }
}

From source file:edu.stolaf.cs.wmrserver.JobServiceHandler.java

public static InternalException wrapException(String message, Throwable cause) {
    InternalException ex = new InternalException(message);

    // Serialize cause chain
    ArrayList<CausingException> causeChain = new ArrayList<CausingException>();
    while (cause != null) {
        CausingException causeStruct = new CausingException();

        causeStruct.setMessage(cause.getMessage());
        causeStruct.setType(cause.getClass().getName());

        // Store stack trace as string
        StringWriter stackTraceWriter = new StringWriter();
        cause.printStackTrace(new PrintWriter(stackTraceWriter));
        causeStruct.setStackTrace(stackTraceWriter.toString());

        causeChain.add(causeStruct);//from www .  ja  v  a2  s  .c  o m

        // Move to next in chain and loop
        cause = cause.getCause();
    }
    ex.setCauses(causeChain);

    return ex;
}