Example usage for org.apache.http.nio.protocol HttpAsyncResponseConsumer getException

List of usage examples for org.apache.http.nio.protocol HttpAsyncResponseConsumer getException

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol HttpAsyncResponseConsumer getException.

Prototype

Exception getException();

Source Link

Document

Returns an exception in case of an abnormal termination.

Usage

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void responseCompleted() throws IOException, HttpException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] Response processed");
    }//from  w  w w  .j  ava2 s .c  o m

    final boolean keepAlive = manageConnectionPersistence();

    final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerRef.getAndSet(null);
    Asserts.check(responseConsumer != null, "Inconsistent state: response consumer is null");
    try {
        responseConsumer.responseCompleted(this.localContext);
        final T result = responseConsumer.getResult();
        final Exception ex = responseConsumer.getException();
        try {
            responseConsumer.close();
        } catch (final IOException ioex) {
            this.log.debug(ioex.getMessage(), ioex);
        }
        if (result != null) {
            this.resultQueue.add(result);
        } else {
            failed(ex);
        }
        if (!this.resultFuture.isDone() && this.responseConsumerQueue.isEmpty()) {
            this.resultFuture.completed(new ArrayList<T>(this.resultQueue));
            this.resultQueue.clear();
        }

        if (this.resultFuture.isDone()) {
            close();
        } else {
            if (!keepAlive) {
                failed(new ConnectionClosedException("Connection closed"));
            } else {
                final NHttpClientConnection localConn = getConnection();
                if (localConn != null) {
                    localConn.requestOutput();
                } else {
                    requestConnection();
                }
            }
        }
    } catch (final RuntimeException ex) {
        failed(ex);
        throw ex;
    }
}