## org.apache.http.impl.nio
Class DefaultNHttpClientConnection

    java.lang.Object
      org.apache.http.impl.nio.NHttpConnectionBase
          org.apache.http.impl.nio.DefaultNHttpClientConnection

All Implemented Interfaces:
  Closeable, HttpConnection, HttpInetConnection, IOControl, NHttpClientConnection, NHttpClientIOTarget, NHttpConnection, SessionBufferStatus, SocketAccessor

    @NotThreadSafe
    public class DefaultNHttpClientConnection

extends NHttpConnectionBase
implements NHttpClientIOTarget

Default implementation of the `NHttpClientConnection` interface.

The following parameters can be used to customize the behavior of this class:

- `CoreProtocolPNames.HTTP_ELEMENT_CHARSET`
- `CoreConnectionPNames.SOCKET_BUFFER_SIZE`
- `CoreConnectionPNames.MAX_HEADER_COUNT`
- `CoreConnectionPNames.MAX_LINE_LENGTH`

Since:
  4.0

Field Summary
`protected NHttpMessageWriter<HttpRequest>` `requestWriter`
`protected NHttpMessageParser<HttpResponse>` `responseParser`

Fields inherited from class org.apache.http.impl.nio.NHttpConnectionBase
`connMetrics, contentDecoder, contentEncoder, context, hasBufferedInput, hasBufferedOutput, inbuf, incomingContentStrategy, inTransportMetrics, outbuf, outgoingContentStrategy, outTransportMetrics, remote, request, response, session, status`

Fields inherited from interface org.apache.http.nio.NHttpConnection
`ACTIVE, CLOSED, CLOSING`

Constructor Summary
`DefaultNHttpClientConnection(IOSession session, HttpResponseFactory responseFactory, ByteBufferAllocator allocator, HttpParams params)` Creates a new instance of this class given the underlying I/O session.

Method Summary
`void` `consumeInput(NHttpClientEventHandler handler)`
`void` `consumeInput(NHttpClientHandler handler)` Triggered when the connection is ready to consume input.
`protected NHttpMessageWriter<HttpRequest>` `createRequestWriter(SessionOutputBuffer buffer, HttpParams params)` Creates an instance of `NHttpMessageWriter` to be used by this connection for writing out outgoing `HttpRequest` messages.
`protected NHttpMessageParser<HttpResponse>` `createResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)` Creates an instance of `NHttpMessageParser` to be used by this connection for parsing incoming `HttpResponse` messages.
`boolean` `isRequestSubmitted()` Returns `true` if an HTTP request has been submitted to the target server.
`protected void` `onRequestSubmitted(HttpRequest request)`
`protected void` `onResponseReceived(HttpResponse response)`
`void` `produceOutput(NHttpClientEventHandler handler)`
`void` `produceOutput(NHttpClientHandler handler)` Triggered when the connection is ready to produce output.
`void` `resetInput()` Resets input state.
`void` `resetOutput()` Resets output state.
`void` `submitRequest(HttpRequest request)` Submits `HttpRequest` to be sent to the target server.

Methods inherited from class org.apache.http.impl.nio.NHttpConnectionBase

`assertNotClosed, bind, close, createConnectionMetrics, createContentDecoder, createContentEncoder, createIncomingContentStrategy, createOutgoingContentStrategy, createTransportMetrics, getContext, getHttpRequest, getHttpResponse, getLocalAddress, getLocalPort, getMetrics, getRemoteAddress, getRemotePort, getSocket, getSocketTimeout, getStatus, hasBufferedInput, hasBufferedOutput, isOpen, isStale, prepareDecoder, prepareEncoder, requestInput, requestOutput, setSocketTimeout, shutdown, suspendInput, suspendOutput, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.apache.http.nio.NHttpConnection
`getContext, getHttpRequest, getHttpResponse, getStatus`

Methods inherited from interface org.apache.http.HttpConnection
`close, getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeout, shutdown`

Methods inherited from interface org.apache.http.nio.IOControl
`requestInput, requestOutput, shutdown, suspendInput, suspendOutput`

Field Detail

### responseParser

    protected final NHttpMessageParser<HttpResponse> responseParser

### requestWriter

    protected final NHttpMessageWriter<HttpRequest> requestWriter

Constructor Detail

### DefaultNHttpClientConnection

    public DefaultNHttpClientConnection(IOSession session,
                                        HttpResponseFactory responseFactory,
                                        ByteBufferAllocator allocator,
                                        HttpParams params)

  Creates a new instance of this class given the underlying I/O session.

  Parameters:
    `session` - the underlying I/O session.
    `responseFactory` - HTTP response factory.
    `allocator` - byte buffer allocator.
    `params` - HTTP parameters.

Method Detail

### createResponseParser

    protected NHttpMessageParser<HttpResponse> createResponseParser(SessionInputBuffer buffer,
                                                                    HttpResponseFactory responseFactory,
                                                                    HttpParams params)

  Creates an instance of `NHttpMessageParser` to be used by this connection for parsing incoming `HttpResponse` messages.

  This method can be overridden in a super class in order to provide a different implementation of the `NHttpMessageParser` interface.

  Returns:
    HTTP response parser.

### createRequestWriter

    protected NHttpMessageWriter<HttpRequest> createRequestWriter(SessionOutputBuffer buffer,
                                                                  HttpParams params)

  Creates an instance of `NHttpMessageWriter` to be used by this connection for writing out outgoing `HttpRequest` messages.

  This method can be overridden by a super class in order to provide a different implementation of the `NHttpMessageWriter` interface.

  Returns:
    HTTP response parser.

### onResponseReceived

    protected void onResponseReceived(HttpResponse response)

  Since:
    4.2

### onRequestSubmitted

    protected void onRequestSubmitted(HttpRequest request)

  Since:
    4.2

### resetInput

    public void resetInput()

  Description copied from interface: `NHttpClientConnection`
  Resets input state. This method can be used to prematurely terminate processing of the incoming HTTP response.

  Specified by:
    `resetInput` in interface `NHttpClientConnection`

### resetOutput

    public void resetOutput()

  Description copied from interface: `NHttpClientConnection`
  Resets output state. This method can be used to prematurely terminate processing of the outgoing HTTP request.

  Specified by:
    `resetOutput` in interface `NHttpClientConnection`

### consumeInput

    public void consumeInput(NHttpClientEventHandler handler)

### produceOutput

    public void produceOutput(NHttpClientEventHandler handler)

### submitRequest

    public void submitRequest(HttpRequest request)
                       throws IOException,
                              HttpException

  Description copied from interface: `NHttpClientConnection`
  Submits `HttpRequest` to be sent to the target server.

  Specified by:
    `submitRequest` in interface `NHttpClientConnection`
  Parameters:
    `request` - HTTP request
  Throws:
    `IOException` - if I/O error occurs while submitting the request
    `HttpException` - if the HTTP request violates the HTTP protocol.

### isRequestSubmitted

    public boolean isRequestSubmitted()

  Description copied from interface: `NHttpClientConnection`
  Returns `true` if an HTTP request has been submitted to the target server.

  Specified by:
    `isRequestSubmitted` in interface `NHttpClientConnection`
  Returns:
    `true` if an HTTP request has been submitted, `false` otherwise.

### consumeInput

    public void consumeInput(NHttpClientHandler handler)

  Description copied from interface: `NHttpClientIOTarget`
  Triggered when the connection is ready to consume input.

  Specified by:
    `consumeInput` in interface `NHttpClientIOTarget`
  Parameters:
    `handler` - the client protocol handler.

### produceOutput

    public void produceOutput(NHttpClientHandler handler)

  Description copied from interface: `NHttpClientIOTarget`
  Triggered when the connection is ready to produce output.

  Specified by:
    `produceOutput` in interface `NHttpClientIOTarget`
  Parameters:
    `handler` - the client protocol handler.

Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.