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:io.ucoin.ucoinj.web.rest.RestResponseEntityExceptionHandler.java

private Throwable getCause(Throwable e, Class... classes) {
    for (Class clazz : classes) {
        if (clazz.isInstance(e)) {
            return e;
        }//from w  w  w.jav  a2s  .  com
    }
    if (e.getCause() != null) {
        return getCause(e.getCause(), classes);
    }
    return null;
}

From source file:org.activiti.rest.common.application.ActivitiStatusService.java

@Override
public Status getStatus(Throwable throwable, Request request, Response response) {
    Status status = null;//from   w w w  .j  a  v a2s .  c o  m
    if (throwable instanceof JsonMappingException && throwable.getCause() != null) {
        // Possible that the Jackson-unmarchalling has a more specific cause. if no specific exception caused
        // the throwable, it will be handled as a normal exception
        status = getSpecificStatus(throwable.getCause(), request, response);
    }

    if (status == null) {
        Throwable causeThrowable = null;
        if (throwable.getCause() != null && throwable.getCause() instanceof ActivitiException) {
            causeThrowable = throwable.getCause();
        } else {
            causeThrowable = throwable;
        }
        status = getSpecificStatus(causeThrowable, request, response);
    }
    return status != null ? status : Status.SERVER_ERROR_INTERNAL;
}

From source file:br.ufac.sion.inscricao.util.jsf.JsfExceptionHandler.java

private ArquivoRetornoException getArquivoRetornoException(Throwable exception) {
    if (exception instanceof ArquivoRetornoException) {
        return (ArquivoRetornoException) exception;
    } else if (exception.getCause() != null) {
        return getArquivoRetornoException(exception.getCause());
    }/*w  w  w . j  a  v a 2 s.  c o  m*/

    return null;
}

From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java

/**
 * Return the cause exception.//from   w  w  w  .ja  va 2s  .c  o m
 *
 * @param exc exception to get message for
 * @return cause exception if any
 */
private Throwable getCause(Throwable exc) {
    Throwable cause = exc.getCause();
    // use the roundabout way to figure out if there is a cause exception if none found easily
    // some classes, like EJBException need to be java 1.3 compatible and have a getCausedByException method
    if (cause == null) {
        Class clazz = exc.getClass();
        try {
            Method method = clazz.getMethod("getCausedByException");
            cause = (Throwable) method.invoke(exc);
        } catch (Exception ex) {
            cause = null; /*ignore*/
        }
    }
    return cause;
}

From source file:com.gargoylesoftware.htmlunit.html.HTMLParser.java

/**
 * Extract nested exception within an XNIException (Nekohtml uses reflection and generated
 * exceptions are wrapped many times within XNIException and InvocationTargetException)
 *
 * @param e the original XNIException//from  ww  w . j a  va2s  .co m
 * @return the cause exception
 */
static Throwable extractNestedException(final Throwable e) {
    Throwable originalException = e;
    Throwable cause = ((XNIException) e).getException();
    while (cause != null) {
        originalException = cause;
        if (cause instanceof XNIException) {
            cause = ((XNIException) cause).getException();
        } else if (cause instanceof InvocationTargetException) {
            cause = cause.getCause();
        } else {
            cause = null;
        }
    }
    return originalException;
}

From source file:com.surevine.alfresco.repo.action.delete.DeleteActionJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    if (_logger.isDebugEnabled()) {
        _logger.debug("Running Delete Action Job...");
    }/*from ww w  .  ja  va2s  .c  o m*/

    //Retrieve job data from the scheduled jobs context
    JobDataMap jobData = context.getJobDetail().getJobDataMap();

    Object actionServiceO = jobData.get("actionService");
    if (actionServiceO == null || !(actionServiceO instanceof ActionService)) {
        throw new AlfrescoRuntimeException(
                "DeleteActionJob data must contain a valid 'actionService' reference");
    }
    ActionService actionService = (ActionService) actionServiceO;

    Object searchServiceO = jobData.get("searchService");
    if (searchServiceO == null || !(searchServiceO instanceof SearchService)) {
        throw new AlfrescoRuntimeException(
                "DeleteActionJob data must contain a valid 'SearchService' reference");
    }
    SearchService searchService = (SearchService) searchServiceO;

    _itemsToDeleteQuery = jobData.getString("itemsToDeleteQuery");
    _itemsToDeleteFilterFailedQuery = jobData.getString("itemsToDeleteFilterFailedQuery");

    if (_logger.isDebugEnabled()) {
        _logger.debug(String.format("Items to delete lucene query: %s .", _itemsToDeleteQuery));
    }
    if (_logger.isDebugEnabled()) {
        _logger.debug(String.format("Items to delete excluding failed lucene query: %s .",
                _itemsToDeleteFilterFailedQuery));
    }

    // Create an Action based on the DeleteAction ActionExecutor
    if (_logger.isDebugEnabled()) {
        _logger.debug("Creating action instance");
    }
    Action actionImpl = actionService.createAction(DeleteAction.NAME);

    if (_logger.isDebugEnabled()) {
        _logger.debug("Finding items due for archival");
    }

    ResultSet rs = null;
    try {
        //Find all items to expire
        rs = searchService.query(STORE_REF, SearchService.LANGUAGE_LUCENE, assembleLuceneQuery());
        Iterator<ResultSetRow> results = rs.iterator();
        if (_logger.isDebugEnabled()) {
            _logger.debug("Found " + rs.length() + " items to archive");
        }

        while (results.hasNext()) {
            NodeRef target = results.next().getNodeRef();
            if (_logger.isInfoEnabled()) {
                _logger.info("Archiving " + target);
            }
            try {
                AuthenticationUtil.runAs(new ExecuteJobWork(actionImpl, target, actionService),
                        AuthenticationUtil.getSystemUserName());
            } catch (Throwable e) {
                if (e.getCause() != null) {
                    e = e.getCause();
                }
                _logger.warn("Could not archive " + target + " due to a " + e, e);
            }
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
    }
}

From source file:gov.nih.nci.cagrid.portal.portlet.workflow.mvc.NewInstanceFormController.java

@Override
protected void processFormSubmission(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    String id = PortletRequestUtils.getStringParameter(request, "id", "NaN");
    log.debug("processFormSubmission. action: "
            + PortletRequestUtils.getStringParameter(request, "action", "NaN") + " | id - " + id);
    SubmitWorkflowCommand cmd = (SubmitWorkflowCommand) command;
    log.debug("Command Object: " + cmd.getTheWorkflow());
    try {//from   ww w. j  av a 2 s .  c om
        WorkflowDescription selectedWorkflow = registry.getWorkflow(id);
        log.info("Submitting the selected workflow.. #" + id);
        String tempFilePath = saveWorkflowDefinition(selectedWorkflow);
        EndpointReferenceType epr = workflowService.submitWorkflow(selectedWorkflow.getName(), tempFilePath,
                cmd.getInputValues());
        UUID uuid = UUID.randomUUID();
        log.debug("Will submit UUID : " + uuid.toString());
        eprs.put(uuid.toString(), new WorkflowSubmitted(epr, selectedWorkflow, "Submitted"));
        cmd.setResult("The Workflow was submitted successfully.");
        log.info("The Workflow was submitted successfully.");
    } catch (Throwable e) {
        log.error("Error submitting workflow", e);
        Throwable ex = e.getCause();
        while (ex.getCause() != null) {
            ex = ex.getCause();
        }
        cmd.setResult(e.getClass().getSimpleName() + " submitting workflow: " + e.getMessage());
    }
}

From source file:ar.com.zauber.garfio.modules.mantis.model.MantisTrackerSession.java

/** @see TrackerSession#issueExists(long) */
public final boolean issueExists(final String issueId) {
    validateIssueId(issueId);//from w  ww. ja  va2s. c o m
    boolean ret = false;
    try {
        final long issue = Long.parseLong(issueId);
        ret = session.issueExists(issue);
        if (ret) {
            // issueExists no siempre funciona bien para verificar que
            // se tiene permiso para accceder
            session.getIssue(issue);
        }

    } catch (final JMTException e) {
        if ("Access Denied".equals(e.getMessage())) {
            ret = false;
        } else {
            Throwable t = e;
            while (t.getCause() != null) {
                t = t.getCause();
            }
            if (t instanceof SAXException && t.getMessage().startsWith("Bad envelope tag:")) {
                ret = false;
            } else {
                throw new RuntimeException(e);
            }

        }
    }
    return ret;
}

From source file:com.gargoylesoftware.htmlunit.libraries.DojoTestBase.java

void test(final String module) throws Exception {
    try {/*w ww .ja  v  a2s .  co  m*/

        final WebDriver webdriver = getWebDriver();
        final String url = "http://localhost:" + PORT + "/util/doh/runner.html?testModule=" + module;
        webdriver.get(url);

        final long runTime = 60 * DEFAULT_WAIT_TIME;
        final long endTime = System.currentTimeMillis() + runTime;

        // wait a bit to let the tests start
        Thread.sleep(DEFAULT_WAIT_TIME);

        String status = getResultElementText(webdriver);
        while (!"Stopped".equals(status)) {
            Thread.sleep(DEFAULT_WAIT_TIME);

            if (System.currentTimeMillis() > endTime) {
                fail("Test runs too long (longer than " + runTime / 1000 + "s)");
            }
            status = getResultElementText(webdriver);
        }

        Thread.sleep(100); // to make tests a bit more stable
        final WebElement output = webdriver.findElement(By.id("logBody"));
        final List<WebElement> lines = output.findElements(By.xpath(".//div"));

        final StringBuilder result = new StringBuilder();
        for (WebElement webElement : lines) {
            final String text = webElement.getText();
            if (StringUtils.isNotBlank(text)) {
                result.append(text);
                result.append("\n");
            }
        }

        String expFileName = StringUtils.replace(module, ".", "");
        expFileName = StringUtils.replace(expFileName, "_", "");
        String expected = loadExpectation(expFileName);
        expected = StringUtils.replace(expected, "\r\n", "\n");

        assertEquals(normalize(expected), normalize(result.toString()));
        // assertEquals(expected, result.toString());
    } catch (final Exception e) {
        e.printStackTrace();
        Throwable t = e;
        while ((t = t.getCause()) != null) {
            t.printStackTrace();
        }
        throw e;
    }
}

From source file:uk.ac.ebi.intact.editor.controller.admin.InstitutionAdminController.java

public void fixReleasableOwners(ActionEvent evt) {
    if (usersDualListModel.getTarget().isEmpty()) {
        addErrorMessage("No users selected", "Add some users to fix using the picklist");
        return;/*from   w ww .  j  a v a 2 s .  c o  m*/
    }

    getInstitutionAdminService().getIntactDao().getUserContext().setUser(getCurrentUser());
    int updatedCount = 0;
    try {
        updatedCount = getInstitutionAdminService().fixReleasableOwners(usersDualListModel.getTarget());
        addInfoMessage("Users object ownership fixed", "Updated annotated objects: " + updatedCount);
    } catch (Throwable e) {
        addErrorMessage("Problem updating user annotated objects", e.getCause() + ": " + e.getMessage());
        log.error("Problem updating user annotated objects", e);
    }

    reloadDataModels();
}