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

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

All Implemented Interfaces:
  Closeable, HttpConnection, HttpInetConnection, IOControl, NHttpConnection, NHttpServerConnection, NHttpServerIOTarget, SessionBufferStatus, SocketAccessor

    @NotThreadSafe
    public class DefaultNHttpServerConnection

extends NHttpConnectionBase
implements NHttpServerIOTarget

Default implementation of the `NHttpServerConnection` 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 NHttpMessageParser<HttpRequest>` `requestParser`
`protected NHttpMessageWriter<HttpResponse>` `responseWriter`

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
`DefaultNHttpServerConnection(IOSession session, HttpRequestFactory requestFactory, ByteBufferAllocator allocator, HttpParams params)` Creates a new instance of this class given the underlying I/O session.

Method Summary
`void` `consumeInput(NHttpServerEventHandler handler)`
`void` `consumeInput(NHttpServiceHandler handler)` Triggered when the connection is ready to consume input.
`protected ContentLengthStrategy` `createIncomingContentStrategy()`
`protected NHttpMessageParser<HttpRequest>` `createRequestParser(SessionInputBuffer buffer, HttpRequestFactory requestFactory, HttpParams params)` Creates an instance of `NHttpMessageParser` to be used by this connection for parsing incoming `HttpRequest` messages.
`protected NHttpMessageWriter<HttpResponse>` `createResponseWriter(SessionOutputBuffer buffer, HttpParams params)` Creates an instance of `NHttpMessageWriter` to be used by this connection for writing out outgoing `HttpResponse` messages.
`boolean` `isResponseSubmitted()` Returns `true` if an HTTP response has been submitted to the client.
`protected void` `onRequestReceived(HttpRequest request)`
`protected void` `onResponseSubmitted(HttpResponse response)`
`void` `produceOutput(NHttpServerEventHandler handler)`
`void` `produceOutput(NHttpServiceHandler handler)` Triggered when the connection is ready to produce output.
`void` `resetInput()` Resets output state.
`void` `resetOutput()` Resets input state.
`void` `submitResponse(HttpResponse response)` Submits {link @HttpResponse} to be sent to the client.

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

`assertNotClosed, bind, close, createConnectionMetrics, createContentDecoder, createContentEncoder, 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

### requestParser

    protected final NHttpMessageParser<HttpRequest> requestParser

### responseWriter

    protected final NHttpMessageWriter<HttpResponse> responseWriter

Constructor Detail

### DefaultNHttpServerConnection

    public DefaultNHttpServerConnection(IOSession session,
                                        HttpRequestFactory requestFactory,
                                        ByteBufferAllocator allocator,
                                        HttpParams params)

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

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

Method Detail

### createIncomingContentStrategy

    protected ContentLengthStrategy createIncomingContentStrategy()

  Overrides:
    `createIncomingContentStrategy` in class `NHttpConnectionBase`

### createRequestParser

    protected NHttpMessageParser<HttpRequest> createRequestParser(SessionInputBuffer buffer,
                                                                  HttpRequestFactory requestFactory,
                                                                  HttpParams params)

  Creates an instance of `NHttpMessageParser` to be used by this connection for parsing incoming `HttpRequest` 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.

### createResponseWriter

    protected NHttpMessageWriter<HttpResponse> createResponseWriter(SessionOutputBuffer buffer,
                                                                    HttpParams params)

  Creates an instance of `NHttpMessageWriter` to be used by this connection for writing out outgoing `HttpResponse` 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.

### onRequestReceived

    protected void onRequestReceived(HttpRequest request)

  Since:
    4.2

### onResponseSubmitted

    protected void onResponseSubmitted(HttpResponse response)

  Since:
    4.2

### resetInput

    public void resetInput()

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

  Specified by:
    `resetInput` in interface `NHttpServerConnection`

### resetOutput

    public void resetOutput()

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

  Specified by:
    `resetOutput` in interface `NHttpServerConnection`

### consumeInput

    public void consumeInput(NHttpServerEventHandler handler)

### produceOutput

    public void produceOutput(NHttpServerEventHandler handler)

### submitResponse

    public void submitResponse(HttpResponse response)
                        throws IOException,
                               HttpException

  Description copied from interface: `NHttpServerConnection`
  Submits {link @HttpResponse} to be sent to the client.

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

### isResponseSubmitted

    public boolean isResponseSubmitted()

  Description copied from interface: `NHttpServerConnection`
  Returns `true` if an HTTP response has been submitted to the client.

  Specified by:
    `isResponseSubmitted` in interface `NHttpServerConnection`
  Returns:
    `true` if an HTTP response has been submitted, `false` otherwise.

### consumeInput

    public void consumeInput(NHttpServiceHandler handler)

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

  Specified by:
    `consumeInput` in interface `NHttpServerIOTarget`
  Parameters:
    `handler` - the server protocol handler.

### produceOutput

    public void produceOutput(NHttpServiceHandler handler)

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

  Specified by:
    `produceOutput` in interface `NHttpServerIOTarget`
  Parameters:
    `handler` - the server protocol handler.

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