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.ganji.cateye.flume.kestrel.KestrelRpcClient.java

License:asdf

@Override
public void appendBatch(List<Event> events) throws EventDeliveryException {
    // Thrift IPC client is not thread safe, so don't allow state changes or client.append* calls unless the lock is acquired.
    ClientWrapper client = null;/*  w w w  . j ava2s . c o  m*/
    boolean destroyedClient = false;
    try {
        if (!isActive()) {
            throw new EventDeliveryException("Client was closed due to error or is not yet configured.");
        }
        client = connectionManager.checkout();
        doAppendBatch(client, events).get(requestTimeout, TimeUnit.MILLISECONDS);
    } catch (Throwable e) {
        if (e instanceof ExecutionException) {
            Throwable cause = e.getCause();
            if (cause instanceof EventDeliveryException) {
                throw (EventDeliveryException) cause;
            } else if (cause instanceof TimeoutException) {
                throw new EventDeliveryException("Append call timeout", cause);
            }
        }
        destroyedClient = true;
        // If destroy throws, we still don't want to reuse the client, so mark it
        // as destroyed before we actually do.
        if (client != null) {
            connectionManager.destroy(client);
        }
        if (e instanceof Error) {
            throw (Error) e;
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new EventDeliveryException("Failed to send event. ", e);
    } finally {
        if (client != null && !destroyedClient) {
            connectionManager.checkIn(client);
        }
    }
}

From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigurationSerialization.java

protected ConfigurationSerializable deserializeViaCtor(Constructor<?> ctor, Map<String, ?> args) {
    try {/*  w w  w .  ja va 2  s .com*/
        return (ConfigurationSerializable) ctor.newInstance(args);
    } catch (Throwable ex) {
        Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
                "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
                ex instanceof InvocationTargetException ? ex.getCause() : ex);
    }

    return null;
}

From source file:org.toobsframework.pres.doit.controller.strategy.DefaultForwardStrategy.java

public AbstractUrlBasedView resolveErrorForward(IRequest componentRequest, DoIt doIt,
        Map<String, Object> forwardParams, Throwable t) {
    AbstractUrlBasedView forwardView = null;

    boolean validationError = false;
    String forwardName = null;//  w  w  w  .  ja  v  a 2 s  .  c om
    Map<String, Object> inputParams = componentRequest.getParams();
    Map<String, Object> responseParams = componentRequest.getResponseParams();

    if (t.getCause() instanceof ValidationException) {
        validationError = true;
        forwardParams.put(VALIDATION_ERROR_MESSAGES, responseParams.get(VALIDATION_ERROR_MESSAGES));
        forwardParams.put(VALIDATION_ERROR_OBJECTS, responseParams.get(VALIDATION_ERROR_OBJECTS));
        //addErrorForwardParams(componentRequest, thisAction, forwardParams, forwardParams);
        componentRequest.getHttpResponse().setHeader(VALIDATION_HEADER_NAME, "true");

    } else if (t.getCause() instanceof PermissionException) {
        PermissionException pe = (PermissionException) t.getCause();
        forwardName = pe.getReason() + PERMISSION_FORWARD_SUFFIX;
    } else if (t instanceof BaseException) {
        componentRequest.getHttpRequest().setAttribute(PresConstants.USER_ERROR_MESSAGES_ATTR_NAME,
                ((BaseException) t).getUserMessages());
    }

    componentRequest.getHttpRequest().setAttribute(PresConstants.TOOBS_EXCEPTION_ATTR_NAME, t);

    log.error("Error running Action: " + t);

    if (forwardName == null) {
        forwardName = getForwardName(ERROR_FORWARD_NAME_PARAM, inputParams);
        if (forwardName == null) {
            forwardName = getForwardName(ERROR_FORWARD_NAME_PARAM, responseParams);
            if (forwardName == null) {
                forwardName = DEFAULT_ERROR_FORWARD_NAME;
            }
        }
    }

    String forwardTo = null;
    Forward toobsForwardDef = getForward(doIt, forwardName);
    boolean forward = false;
    if (toobsForwardDef != null) {
        forwardTo = ParameterUtil.resoveForwardPath(componentRequest, toobsForwardDef,
                componentRequest.getHttpRequest().getParameterMap());
        forward = toobsForwardDef.getForward();
    } else if (validationError) {
        forwardTo = getReferer(componentRequest.getHttpRequest());
    }
    if (forwardTo == null || forwardTo.length() == 0) {
        componentRequest.getHttpResponse().setHeader(PresConstants.TOOBS_EXCEPTION_HEADER_NAME, "true");
        forwardTo = this.getReferer(componentRequest.getHttpRequest());
    }
    if (forward || validationError) {
        forwardView = new InternalResourceView(forwardTo);
    } else {
        forwardView = new InternalResourceView(forwardTo);
        //forwardView = new RedirectView(forwardTo, true);
    }
    return forwardView;
}

From source file:de.ingrid.portal.interfaces.impl.IBUSInterfaceImpl.java

/**
 * @see de.ingrid.portal.interfaces.IBUSInterface#getRecord(de.ingrid.utils.IngridHit)
 *//*from  w  w  w.  j a  va 2 s  . co m*/
public Record getRecord(IngridHit result) {
    Record rec = null;

    injectCache(result);

    try {
        rec = bus.getRecord(result);
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Problems fetching Record of result: " + result + "[cause:" + t.getCause() + "]", t);
        } else if (log.isInfoEnabled()) {
            log.info("Problems fetching Record of result: " + result + "[cause:" + t.getCause() + "]");
        } else {
            log.warn("Problems fetching Record of result: " + result + "[cause:" + t.getCause() + "]", t);
        }
    }

    return rec;
}

From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigurationSerialization.java

protected ConfigurationSerializable deserializeViaMethod(Method method, Map<String, ?> args) {
    try {//from www .  j  av  a  2s .co  m
        ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, args);

        if (result == null) {
            Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
                    "Could not call method '" + method.toString() + "' of " + clazz
                            + " for deserialization: method returned null");
        } else {
            return result;
        }
    } catch (Throwable ex) {
        Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE,
                "Could not call method '" + method.toString() + "' of " + clazz + " for deserialization",
                ex instanceof InvocationTargetException ? ex.getCause() : ex);
    }

    return null;
}

From source file:de.tudarmstadt.lt.lm.service.UimaStringProvider.java

public List<String> getSequenceFromSentence(Sentence sentence) throws Exception {
    boolean handle_sentence_boundaries = Properties.handleBoundaries() == 3; // FIXME:

    List<String> sequence = new ArrayList<String>();
    for (int i = 0; i < getLanguageModel().getOrder() - 1 && handle_sentence_boundaries; i++)
        sequence.add(PseudoSymbol.SEQUENCE_START.asString());

    try {/* w w  w. ja  v  a2  s  .  co m*/
        List<Token> tokens = JCasUtil.selectCovered(Token.class, sentence);
        // Collections.sort(tokens, AnnotationBeginOffsetOrderComparator.INSTANCE);

        int token_count = 0;
        boolean filtered_last_token = false;
        for (Iterator<Token> iter = tokens.iterator(); iter.hasNext();) {
            Token token = iter.next();
            if (!JCasUtil.selectCovered(FilteredItem.class, token).isEmpty()) {
                if (!filtered_last_token && Properties.mergeFilteredItems()) {
                    sequence.add("<filtered>");
                    token_count++;
                    filtered_last_token = true;
                }
                continue;
            }
            filtered_last_token = false;

            if (Properties.ignorePunctuation() && token.getPos() instanceof PUNC)
                continue;
            String word;
            if (Properties.ignorePunctuation() && token.getLemma() != null
                    && token.getLemma().getValue() != null)
                word = token.getLemma().getValue();
            else
                word = token.getCoveredText();

            word = de.tudarmstadt.lt.utilities.StringUtils.trim_and_replace_emptyspace(word, "_");
            if (Properties.useLowercase())
                word = word.toLowerCase();
            sequence.add(word);
            token_count++;
        }

        if (token_count < getLanguageModel().getOrder())
            return Collections.emptyList();

    } catch (Throwable t) {
        while (t != null) {
            LOG.error(String.format("Error while processing sentence. %s:%s", t.getClass().getName(),
                    t.getMessage()), t);
            t = t.getCause();
        }
    }

    //      sequence.add(PseudoSymbol.SEQUENCE_END.asString());
    return sequence;
}

From source file:com.netflix.niws.client.http.SecureAcceptAllGetTest.java

@Test
public void testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore() throws Exception {

    // test config exception happens before we even try to connect to anything

    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();

    String name = "GetPostSecureTest" + ".testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore";

    String configPrefix = name + "." + "ribbon";

    cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName,
            "com.netflix.http4.ssl.AcceptAllSocketFactory");
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, TEST_FILE_TS.getAbsolutePath());
    cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);

    boolean foundCause = false;

    try {// w  ww. j av  a  2  s . co  m

        ClientFactory.getNamedClient(name);

    } catch (Throwable t) {

        while (t != null && !foundCause) {

            if (t instanceof IllegalArgumentException && t.getMessage()
                    .startsWith("Invalid value associated with property:CustomSSLSocketFactoryClassName")) {
                foundCause = true;
                break;
            }

            t = t.getCause();
        }
    }

    assertTrue(foundCause);

}

From source file:de.ingrid.portal.interfaces.impl.IBUSInterfaceImpl.java

/**
 * @see de.ingrid.portal.interfaces.IBUSInterface#getDetail(de.ingrid.utils.IngridHit,
 * de.ingrid.utils.query.IngridQuery, java.lang.String[])
 */// w w  w  .  j  ava2 s.  c  o  m
public IngridHitDetail getDetail(IngridHit result, IngridQuery query, String[] requestedFields) {
    IngridHitDetail detail = null;

    injectCache(query);

    String s = DeepUtil.deepString(query, 1);

    try {
        if (log.isDebugEnabled()) {
            log.debug("iBus.getDetail: hit = " + result + ", requestedFields = " + requestedFields);
        }
        long start = System.currentTimeMillis();
        detail = bus.getDetail(result, query, requestedFields);

        if (log.isDebugEnabled()) {
            long duration = System.currentTimeMillis() - start;
            log.debug("iBus.getDetail: finished !");
            log.debug("in " + duration + "ms");
        }
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Problems fetching Detail of results: " + result + "[cause:" + t.getCause().getMessage()
                    + "]", t);
        } else if (log.isInfoEnabled()) {
            log.info("Problems fetching Detail of results: " + result + "[cause:" + t.getCause().getMessage()
                    + "]");
        } else {
            log.warn("Problems fetching Detail of results: " + result + "[cause:" + t.getCause().getMessage()
                    + "]", t);
        }
    }

    return detail;
}

From source file:jp.co.opentone.bsol.linkbinder.view.ErrorPage.java

public void fillStackTrace(Throwable ex, PrintWriter pw) {
    if (ex == null) {
        return;/*from  w w w.  j  a v a  2  s.  c o m*/
    }

    ex.printStackTrace(pw);
    if (ex instanceof ServletException) {
        Throwable cause = ((ServletException) ex).getRootCause();
        if (cause != null) {
            pw.println("Root Cause: ");
            fillStackTrace(cause, pw);
        }
    } else {
        Throwable cause = ex.getCause();
        if (cause != null) {
            pw.println("Cause: ");
            fillStackTrace(cause, pw);
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.services.LocalizationServiceImpl.java

/**
 * Gets the localized exception message//from  w ww . j a v a2s  .  co m
 *
 * @param t
 * @return localized string
 */
public String getExceptionMessage(final Throwable t) {

    //get exception message
    String message = t.getLocalizedMessage();

    if (t instanceof TeamServicesException) {
        final String key = ((TeamServicesException) t).getMessageKey();
        if (keysMap.containsKey(key)) {
            message = getLocalizedMessage(keysMap.get(key));
        }
    }

    //exception message is not set
    //Use the message on the cause if there is one
    if (StringUtils.isEmpty(message) && t.getCause() != null) {
        if (t.getCause() instanceof TeamServicesException) {
            final String key = ((TeamServicesException) t).getMessageKey();
            if (keysMap.containsKey(key)) {
                message = getLocalizedMessage(keysMap.get(key));
            }
        } else {
            message = t.getCause().getLocalizedMessage();
        }
    }

    //No message on the exception and the cause, just use description from toString
    if (StringUtils.isEmpty(message)) {
        message = t.toString();
    }

    return message;
}