Example usage for org.apache.http.impl.nio.reactor ExceptionEvent getCause

List of usage examples for org.apache.http.impl.nio.reactor ExceptionEvent getCause

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.reactor ExceptionEvent getCause.

Prototype

public Throwable getCause() 

Source Link

Usage

From source file:co.paralleluniverse.fibers.httpclient.FiberHttpClient.java

@Override
@Suspendable//from   w  w  w.  ja v a2 s  . co  m
protected final CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request,
        final HttpContext context) throws IOException, ClientProtocolException {
    try {
        for (int executionCount = 0;; executionCount++) {
            try {
                final HttpResponse response = new AsyncHttpReq() {
                    @Override
                    protected void requestAsync() {
                        client.execute(target, request, context, this);
                    }
                }.run();
                return new CloseableHttpResponseWrapper(response);
            } catch (IOException ex) {
                if (httpRequestRetryHandler != null
                        && httpRequestRetryHandler.retryRequest(ex, executionCount, context)) {
                    if (this.log.isInfoEnabled()) {
                        this.log.info("I/O exception (" + ex.getClass().getName()
                                + ") caught when processing request: " + ex.getMessage());
                    }
                    if (this.log.isDebugEnabled()) {
                        this.log.debug(ex.getMessage(), ex);
                    }
                    this.log.info("Retrying request");
                } else
                    throw ex;
            }
        }
    } catch (SuspendExecution e) {
        throw new AssertionError();
    } catch (IllegalStateException ise) {
        if (ioreactor != null) {
            final List<ExceptionEvent> events = ioreactor.getAuditLog();
            if (events != null) {
                for (ExceptionEvent event : events) {
                    final StringBuilder msg = new StringBuilder();
                    msg.append("Apache Async HTTP Client I/O Reactor exception timestamp: ");
                    msg.append(event.getTimestamp());
                    if (event.getCause() != null) {
                        msg.append(", cause stacktrace:\n");
                        final StringWriter sw = new StringWriter();
                        final PrintWriter pw = new PrintWriter(sw);
                        ise.getCause().printStackTrace(pw);
                        msg.append(sw.toString());
                    }
                    this.log.fatal(msg.toString());
                }
            }
        }
        throw ise;
    }
}