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.predic8.membrane.core.rules.SOAPProxy.java

/**
 * @return error or null for success/*w  ww . ja  va  2s  .co  m*/
 */
private void parseWSDL() throws Exception {
    WSDLParserContext ctx = new WSDLParserContext();
    ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
    try {
        WSDLParser wsdlParser = new WSDLParser();
        wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());

        Definitions definitions = wsdlParser.parse(ctx);

        List<Service> services = definitions.getServices();
        if (services.size() != 1)
            throw new IllegalArgumentException("There are " + services.size()
                    + " services defined in the WSDL, but exactly 1 is required for soapProxy.");
        Service service = services.get(0);

        if (StringUtils.isEmpty(name))
            name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName();

        List<Port> ports = service.getPorts();
        Port port = selectPort(ports, portName);

        String location = port.getAddress().getLocation();
        if (location == null)
            throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port.");
        try {
            URL url = new URL(location);
            target.setHost(url.getHost());
            if (url.getPort() != -1)
                target.setPort(url.getPort());
            else
                target.setPort(url.getDefaultPort());
            if (key.getPath() == null) {
                key.setUsePathPattern(true);
                key.setPathRegExp(false);
                key.setPath(url.getPath());
            } else {
                targetPath = url.getPath();
            }
            if (location.startsWith("https")) {
                SSLParser sslOutboundParser = new SSLParser();
                target.setSslParser(sslOutboundParser);
            }
            ((ServiceProxyKey) key).setMethod("*");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e);
        }
        return;
    } catch (Exception e) {
        Throwable f = e;
        while (f.getCause() != null && !(f instanceof ResourceRetrievalException))
            f = f.getCause();
        if (f instanceof ResourceRetrievalException) {
            ResourceRetrievalException rre = (ResourceRetrievalException) f;
            if (rre.getStatus() >= 400)
                throw rre;
            Throwable cause = rre.getCause();
            if (cause != null) {
                if (cause instanceof UnknownHostException)
                    throw (UnknownHostException) cause;
                else if (cause instanceof ConnectException)
                    throw (ConnectException) cause;
            }
        }
        throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e);
    }
}

From source file:info.magnolia.ui.admincentral.AdmincentralErrorHandler.java

private Message getErrorMessage(Throwable e) {

    Message message = new Message();
    message.setType(MessageType.ERROR);//from   w  w w . j a v  a  2s .  c  o m

    addMessageDetails(message, e);

    // append details for RPC exceptions
    if (e instanceof RpcInvocationException) {
        e = e.getCause();
        addMessageDetails(message, e);
    }
    if (e instanceof InvocationTargetException) {
        e = ((InvocationTargetException) e).getTargetException();
        addMessageDetails(message, e);
    }
    if (e instanceof MethodException) {
        e = e.getCause();
        addMessageDetails(message, e);
    }

    // append other potential causes
    while (e != null && e != e.getCause()) {
        e = e.getCause();
        addMessageDetails(message, e);
    }

    if (StringUtils.isBlank(message.getSubject())) {
        message.setSubject(DEFAULT_MESSAGE);
    }

    return message;
}

From source file:br.com.suricattus.surispring.jsf.exception.PrettyExceptionHandler.java

@Override
public void handle() throws FacesException {
    catched = false;// ww w . j  a  v a2s.  c om

    for (final Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator(); it
            .hasNext();) {
        Throwable t = it.next().getContext().getException();
        while ((t instanceof FacesException || t instanceof ELException
                || t instanceof UnexpectedRollbackException || t instanceof RollbackException)
                && t.getCause() != null) {
            t = t.getCause();
        }

        if (handleException(it, t, FacesFileNotFoundException.class,
                "com.sun.faces.context.FacesFileNotFoundException.message"))
            continue;
        if (handleException(it, t, PrettyException.class, "com.ocpsoft.pretty.PrettyException.message"))
            continue;
        if (handleException(it, t, EntityNotFoundException.class,
                "javax.persistence.EntityNotFoundException.message"))
            continue;
        if (handleException(it, t, EntityExistsException.class,
                "javax.persistence.EntityExistsException.message"))
            continue;
        if (handleException(it, t, OptimisticLockException.class,
                "javax.persistence.OptimisticLockException.message"))
            continue;
        if (handleException(it, t, ViewExpiredException.class,
                "javax.faces.application.ViewExpiredException.message"))
            continue;
        if (handleException(it, t, Exception.class, "java.lang.Exception.message"))
            continue;

    }
    getWrapped().handle();
}

From source file:io.wcm.caravan.io.http.impl.ResilientHttpImpl.java

private Throwable mapToKnownException(String serviceName, Request request, Throwable ex) {
    if (ex instanceof RequestFailedRuntimeException || ex instanceof IllegalResponseRuntimeException) {
        return ex;
    }//ww w.j  av  a  2  s .  co m
    if (ex instanceof HystrixRuntimeException && ex.getCause() != null) {
        return mapToKnownException(serviceName, request, ex.getCause());
    }
    throw new RequestFailedRuntimeException(serviceName, request,
            StringUtils.defaultString(ex.getMessage(), ex.getClass().getSimpleName()), ex);
}

From source file:com.haulmont.cuba.gui.exception.DeletePolicyHandler.java

@Override
public boolean handle(Throwable exception, WindowManager windowManager) {
    Throwable t = exception;
    try {/*from   ww  w.  j a  v  a2  s.co m*/
        while (t != null) {
            if (t.toString().contains(getMarker())) {
                doHandle(t.toString(), windowManager);
                return true;
            }
            t = t.getCause();
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.talend.dataprep.command.GenericCommand.java

@Override
protected RuntimeException decomposeException(Exception e) {
    Throwable current = e;
    while (current.getCause() != null) {
        if (current instanceof TDPException) {
            break;
        }//from w  ww.  ja v  a2  s  .  c  o  m
        current = current.getCause();
    }
    if (current instanceof TDPException) {
        return (TDPException) current;
    } else {
        return super.decomposeException(e);
    }
}

From source file:com.amalto.core.util.Util.java

public static <T> T getException(Throwable throwable, Class<T> cls) {
    if (cls.isInstance(throwable)) {
        return (T) throwable;
    }//from   w w w  .  ja  va  2s  .c o m
    if (throwable.getCause() != null) {
        return getException(throwable.getCause(), cls);
    }
    return null;
}

From source file:com.bstek.dorado.view.resolver.ViewServiceResolver.java

/**
 * @param jsonBuilder// www  . jav a 2s .c  o m
 * @param e
 */
protected void outputException(JsonBuilder jsonBuilder, Throwable throwable) {
    while (throwable.getCause() != null) {
        throwable = throwable.getCause();
    }

    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getSimpleName();
    }

    try {
        jsonBuilder.object(); // TODO: ?JSONBuilder?
        jsonBuilder.key("exceptionType").value("JavaException").key("message").value(message).key("stackTrace");
        jsonBuilder.array();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            jsonBuilder.value(stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '('
                    + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')');
        }
        jsonBuilder.endArray();
        jsonBuilder.endObject();
    } catch (Exception e) {
        // ignore e!!!
        throwable.printStackTrace();
    }
}

From source file:de.tudarmstadt.lt.ltbot.text.BoilerpipeTextExtractor.java

@Override
public String getPlaintext(final String htmltext) {
    try {//from   w  w w. j  a  v  a  2  s .c o  m
        String plaintext = ArticleExtractor.getInstance().getText(htmltext);
        return plaintext;
    } catch (Throwable t) {
        for (int i = 1; t != null && i < 10; i++) {
            LOG.log(Level.SEVERE,
                    String.format("Failed to get plaintext from while '%s' (%d %s:%s).",
                            StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()),
                    t);
            t = t.getCause();
        }
        return "Failed to get plaintext content \n" + htmltext;
    }
}

From source file:org.gradle.caching.http.internal.HttpBuildCacheService.java

@Override
public void store(BuildCacheKey key, final BuildCacheEntryWriter output) throws BuildCacheException {
    final URI uri = root.resolve(key.getHashCode());
    HttpPut httpPut = new HttpPut(uri);
    httpPut.addHeader(HttpHeaders.CONTENT_TYPE, BUILD_CACHE_CONTENT_TYPE);
    addDiagnosticHeaders(httpPut);/*from  w w  w.  j a va 2s  .  co m*/

    httpPut.setEntity(new AbstractHttpEntity() {
        @Override
        public boolean isRepeatable() {
            return false;
        }

        @Override
        public long getContentLength() {
            return output.getSize();
        }

        @Override
        public InputStream getContent() throws IOException, UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void writeTo(OutputStream outstream) throws IOException {
            output.writeTo(outstream);
        }

        @Override
        public boolean isStreaming() {
            return false;
        }
    });
    CloseableHttpResponse response = null;
    try {
        response = httpClientHelper.performHttpRequest(httpPut);
        StatusLine statusLine = response.getStatusLine();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Response for PUT {}: {}", safeUri(uri), statusLine);
        }
        int statusCode = statusLine.getStatusCode();
        if (!isHttpSuccess(statusCode)) {
            String defaultMessage = String.format("Storing entry at '%s' response status %d: %s", safeUri(uri),
                    statusCode, statusLine.getReasonPhrase());
            if (isRedirect(statusCode)) {
                handleRedirect(uri, response, statusCode, defaultMessage, "storing entry at");
            } else {
                throwHttpStatusCodeException(statusCode, defaultMessage);
            }
        }
    } catch (ClientProtocolException e) {
        Throwable cause = e.getCause();
        if (cause instanceof NonRepeatableRequestException) {
            throw wrap(cause.getCause());
        } else {
            throw wrap(cause);
        }
    } catch (IOException e) {
        throw wrap(e);
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}