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

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

Introduction

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

Prototype

T getResult();

Source Link

Document

Returns a result of the response processing, when available.

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  ww  . j  ava  2s .  co  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;
    }
}