Example usage for org.apache.http.impl.nio.client InternalState setFinalResponse

List of usage examples for org.apache.http.impl.nio.client InternalState setFinalResponse

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client InternalState setFinalResponse.

Prototype

public void setFinalResponse(final HttpResponse finalResponse) 

Source Link

Usage

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

@Override
public void responseReceived(final HttpResponse response, final InternalState state,
        final AbstractClientExchangeHandler<?> handler) throws IOException, HttpException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + state.getId() + "] Response received " + response.getStatusLine());
    }/*from ww  w.j  a  v  a 2s .  co m*/
    final HttpClientContext context = state.getLocalContext();
    context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
    this.httpProcessor.process(response, context);

    handler.setCurrentResponse(response);

    if (!handler.isRouteEstablished()) {
        final int status = response.getStatusLine().getStatusCode();
        if (status < 200) {
            throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine());
        }
        if (status == HttpStatus.SC_OK) {
            handler.onRouteTunnelToTarget();
            handler.setCurrentRequest(null);
        } else {
            if (!handleConnectResponse(state, handler)) {
                state.setFinalResponse(response);
            }
        }
    } else {
        if (!handleResponse(state, handler)) {
            state.setFinalResponse(response);
        }
    }
    if (state.getFinalResponse() != null) {
        final HttpAsyncResponseConsumer<?> responseConsumer = state.getResponseConsumer();
        responseConsumer.responseReceived(response);
    }
}