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.wcm.caravan.io.http.impl.ribbon.RibbonHttpClientTest.java

@Test(expected = ClientException.class)
public void test_retryOnMultipleServersThrowing500() throws ClientException {
    context.registerInjectActivateService(new CaravanHttpServiceConfig(),
            ImmutableMap.<String, Object>builder()
                    .put(CaravanHttpServiceConfig.SERVICE_ID_PROPERTY, SERVICE_NAME)
                    .put(CaravanHttpServiceConfig.RIBBON_HOSTS_PROPERTY,
                            Lists.newArrayList(defectServer1Host, defectServer2Host))
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIES_PROPERTY, 0)
                    .put(CaravanHttpServiceConfig.RIBBON_MAXAUTORETRIESNEXTSERVER_PROPERTY, 9).build());
    try {//w ww.ja  va  2 s . c  om
        client.execute(new CaravanHttpRequestBuilder(SERVICE_NAME).append(HTTP_200_URI).build()).toBlocking()
                .single();
    } catch (Throwable ex) {
        defectServer1.verify(5, WireMock.getRequestedFor(WireMock.urlEqualTo(HTTP_200_URI)));
        defectServer2.verify(5, WireMock.getRequestedFor(WireMock.urlEqualTo(HTTP_200_URI)));
        throw (ClientException) ex.getCause();
    }
}

From source file:jp.xet.uncommons.wicket.utils.ErrorReportRequestCycleListener.java

List<Throwable> getThrowableList(Throwable throwable) {
    List<Throwable> list = new ArrayList<Throwable>();
    while (throwable != null && list.contains(throwable) == false) {
        list.add(throwable);/*from   www .j  a va 2  s .c  om*/
        throwable = throwable.getCause();
    }
    return list;
}

From source file:com.flexive.faces.messages.FxFacesMessage.java

/**
 * Extracts the message of the exception, and set the this.id property in
 * case of a found FxInvalidParameterException.
 *
 * @param exc        the Exception the exception to process
 * @param setDetail  set the detail to the message of the exception
 * @param setSummary set the summaray to the message of the exception
 *//*from w  w w . j  a  v a2  s .  c o m*/
private void processException(Throwable exc, boolean setDetail, boolean setSummary) {
    if (exc == null) {
        return; // don't fail if a null exception was set
    }
    // Try to find a FX__ type within the exception stack
    Throwable tmp = exc;
    while (!isFxThrowable(tmp) && tmp.getCause() != null) {
        tmp = tmp.getCause();
    }

    // If we found a FX__ type we use it
    if (isFxThrowable(tmp)) {
        exc = tmp;
    }

    // Obtain id of the invalid parameter
    if (exc instanceof FxInvalidParameterException) {
        this.id = ((FxInvalidParameterException) exc).getParameter();
    }

    String msg;
    if (exc instanceof FxLocalizedException) {
        UserTicket ticket = FxContext.getUserTicket();
        FxLocalizedException le = ((FxLocalizedException) exc);
        msg = le.getMessage(ticket);
    } else {
        msg = (exc.getMessage() == null) ? String.valueOf(exc.getClass()) : exc.getMessage();
    }

    if (setSummary) {
        setSummary(msg);
    }

    if (setDetail) {
        String sDetail = "";
        if (exc.getCause() != null) {
            String sCause;
            sCause = exc.getCause().getMessage();
            if (sCause == null || sCause.trim().length() == 0 || sCause.equalsIgnoreCase("null")) {
                sCause = exc.getCause().getClass().getName();
            }
            sDetail += "Cause message: " + sCause + "\n\t";
        }
        sDetail += getStackTrace(exc);
        setDetail(sDetail);
    }
}

From source file:controllers.DeveloperController.java

@RequestMapping(value = "/edit", method = RequestMethod.POST, params = "save")
public ModelAndView saveEdit(@Valid final CreateDeveloperForm createDeveloperForm,
        final BindingResult binding) {

    ModelAndView result;//from ww  w  . ja  v  a 2  s.c om
    Developer developer;

    if (binding.hasErrors())
        result = this.editionEditModelAndView(createDeveloperForm);
    else
        try {
            developer = this.developerService.reconstructProfile(createDeveloperForm, "edit");
            this.developerService.save(developer);
            result = new ModelAndView("redirect:/welcome/index.do");

        } catch (final Throwable oops) {
            if (!createDeveloperForm.getPassword().equals(createDeveloperForm.getConfirmPassword()))
                result = this.editionEditModelAndView(createDeveloperForm, "developer.commit.error.password");
            else if ((oops.getCause().getCause().getMessage() != null)
                    && (oops.getCause().getCause().getMessage().contains("Duplicate")))
                result = this.editionEditModelAndView(createDeveloperForm, "developer.commit.error.duplicate");
            else
                result = this.editionEditModelAndView(createDeveloperForm, "developer.commit.error");

        }
    return result;
}

From source file:com.baasbox.service.scripting.js.Nashorn.java

/**
 * Script call evaluation/*from ww  w . j  av  a 2s  .  co m*/
 * @param call
 * @return
 * @throws ScriptEvalException
 */
ScriptResult eval(ScriptCall call) throws ScriptEvalException {
    try {
        ScriptObjectMirror moduleRef = getModule(call);

        if (call.event == null) {
            return null;
        }

        Object result = emitEvent(moduleRef, call.event, call.eventData);
        ScriptResult scriptResult = mMapper.convertResult(result);
        call.validate(scriptResult);
        if (BaasBoxLogger.isTraceEnabled())
            BaasBoxLogger.trace("ScriptResult: %s", scriptResult.toString());
        return scriptResult;
    } catch (Throwable err) {
        if (err instanceof NashornException) {
            if (BaasBoxLogger.isTraceEnabled())
                BaasBoxLogger.trace("Error in script");

            Throwable cause = err.getCause();
            NashornException exc = ((NashornException) err);
            String scriptStack = NashornException.getScriptStackString(exc);
            scriptStack = ExceptionUtils.getFullStackTrace(exc);
            int columnNumber = exc.getColumnNumber();
            int lineNumber = exc.getLineNumber();
            String fileName = exc.getFileName();
            String message = exc.getMessage();
            String errorMessage = String.format("ScriptError: '%s' at: <%s>%d:%d\n%s", message, fileName,
                    lineNumber, columnNumber, scriptStack);
            throw new ScriptEvalException(errorMessage, err);
        }
        throw new ScriptEvalException(ExceptionUtils.getFullStackTrace(err), err);
    }
}

From source file:cc.kune.core.server.LoggerMethodInterceptor.java

/**
 * Log exception.//from  w  w w. java2  s  . c om
 * 
 * @param invocation
 *          the invocation
 * @param e
 *          the e
 */
protected void logException(final MethodInvocation invocation, final Throwable e) {
    final StringBuffer buffer = createBuffer(invocation);
    addMethodName(invocation, buffer);
    buffer.append(" EXCEPTION => ").append(e.getClass()).append(": ")
            .append(e.getCause() != null ? e.getCause() : "")
            .append(e.getMessage() != null ? e.getMessage() : "");
    log(buffer.toString());
}

From source file:com.javaforge.tapestry.acegi.filter.ExceptionTranslationFilter.java

public void presentException(IRequestCycle requestCycle, Throwable exception,
        ExceptionPresenter exceptionPresenter) {
    Throwable rootCause = exception;

    while (rootCause instanceof ServletException) {
        rootCause = exception.getCause();
    }//w  w w . j  a  v a  2 s  . com

    if (rootCause instanceof BindingException) {
        rootCause = exception.getCause();
    }

    if (rootCause instanceof ApplicationRuntimeException) {
        rootCause = exception.getCause();
    }

    try {
        if (rootCause instanceof AuthenticationException) {
            if (getLog().isDebugEnabled()) {
                getLog().debug("Authentication exception occurred; redirecting to authentication entry point",
                        rootCause);
            }

            sendStartAuthentication((AuthenticationException) rootCause);
        } else if (rootCause instanceof AccessDeniedException) {
            if (authenticationTrustResolver
                    .isAnonymous(SecurityContextHolder.getContext().getAuthentication())) {
                if (getLog().isDebugEnabled()) {
                    getLog().debug(
                            "Access is denied (user is anonymous); redirecting to authentication entry point",
                            rootCause);
                }

                sendStartAuthentication(new InsufficientAuthenticationException(
                        "Full authentication is required to access this resource"));
            } else {
                if (getLog().isDebugEnabled()) {
                    getLog().debug(
                            "Access is denied (user is not anonymous); delegating to AccessDeniedHandler",
                            exception);
                }

                accessDeniedHandler.handle(request, response, (AccessDeniedException) rootCause);
            }
        } else {
            exceptionPresenter.presentException(requestCycle, exception);
        }
    } catch (ServletException e) {
        exceptionPresenter.presentException(requestCycle, e);
    } catch (IOException e) {
        exceptionPresenter.presentException(requestCycle, e);
    }
}

From source file:com.comcast.viper.flume2storm.sink.StormSink.java

/**
 * @see org.apache.flume.Sink#process()/*from  w w  w.j a v  a 2s  .com*/
 */
@Override
public Status process() throws EventDeliveryException {
    if (eventSender.getStats().getNbClients() == 0) {
        // No receptor connected
        return Status.BACKOFF;
    }
    Status result = Status.READY;
    final Channel channel = getChannel();
    final Transaction transaction = channel.getTransaction();
    try {
        transaction.begin();
        List<F2SEvent> batch = new ArrayList<F2SEvent>(configuration.getBatchSize());
        for (int i = 0; i < configuration.getBatchSize(); i++) {
            final Event event = channel.take();
            if (event == null) {
                break;
            }
            batch.add(eventConverter.convert(event));
        }
        if (batch.isEmpty()) {
            sinkCounter.incrementBatchEmptyCount();
            result = Status.BACKOFF;
        } else {
            sinkCounter.addToEventDrainAttemptCount(batch.size());
            if (eventSender.send(batch) == 0) {
                throw new EventDeliveryException("No event sent to receptor");
            }
            sinkCounter.addToEventDrainSuccessCount(batch.size());
            if (batch.size() == configuration.getBatchSize()) {
                sinkCounter.incrementBatchCompleteCount();
            } else {
                sinkCounter.incrementBatchUnderflowCount();
            }
        }
        transaction.commit();
    } catch (final Throwable t) {
        transaction.rollback();
        if (t instanceof Error) {
            throw (Error) t;
        } else if (t instanceof ChannelException) {
            if (!(t.getCause() instanceof InterruptedException)) {
                LOG.error("Storm Sink " + getName() + ": Unable to get event from channel " + channel.getName(),
                        t);
            }
            result = Status.BACKOFF;
        } else {
            throw new EventDeliveryException("Failed to accept events", t);
        }
    } finally {
        transaction.close();
    }
    return result;
}

From source file:com.datatopia.clockwork.core.reportng.ReportNGUtils.java

/**
 * Convert a Throwable into a list containing all of its causes.
 * @param t The throwable for which the causes are to be returned.
 * @return A (possibly empty) list of {@link Throwable}s.
 *///from   ww  w.  j a  va2s .  co m
public List<Throwable> getCauses(Throwable t) {
    List<Throwable> causes = new LinkedList<Throwable>();
    Throwable next = t;
    while (next.getCause() != null) {
        next = next.getCause();
        causes.add(next);
    }
    return causes;
}

From source file:maspack.fileutil.FileCacher.java

private Throwable getBaseThrowable(Throwable b) {
    Throwable out = b;
    while (out.getCause() != null && out.getCause() != out) {
        out = out.getCause();/*from  w  w w  . j  a  v a  2 s.  c  om*/
    }
    return out;
}