java.io.Closeable, java.lang.AutoCloseable, org.apache.http.HttpConnection, org.apache.http.HttpInetConnection, IOControl, NHttpConnection, SessionBufferStatus, SocketAccessorDefaultNHttpClientConnection, DefaultNHttpServerConnectionpublic class NHttpConnectionBase extends java.lang.Object implements NHttpConnection, org.apache.http.HttpInetConnection, SessionBufferStatus, SocketAccessor
NHttpConnection implementations and provides
functionality common to both client and server HTTP connections.| Modifier and Type | Field | Description |
|---|---|---|
protected org.apache.http.impl.HttpConnectionMetricsImpl |
connMetrics |
|
protected ContentDecoder |
contentDecoder |
|
protected ContentEncoder |
contentEncoder |
|
protected org.apache.http.protocol.HttpContext |
context |
|
protected boolean |
hasBufferedInput |
|
protected boolean |
hasBufferedOutput |
|
protected SessionInputBufferImpl |
inbuf |
|
protected org.apache.http.entity.ContentLengthStrategy |
incomingContentStrategy |
|
protected org.apache.http.impl.io.HttpTransportMetricsImpl |
inTransportMetrics |
|
protected SessionOutputBufferImpl |
outbuf |
|
protected org.apache.http.entity.ContentLengthStrategy |
outgoingContentStrategy |
|
protected org.apache.http.impl.io.HttpTransportMetricsImpl |
outTransportMetrics |
|
protected java.net.SocketAddress |
remote |
|
protected org.apache.http.HttpRequest |
request |
|
protected org.apache.http.HttpResponse |
response |
|
protected IOSession |
session |
|
protected int |
status |
ACTIVE, CLOSED, CLOSING| Modifier | Constructor | Description |
|---|---|---|
protected |
NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
java.nio.charset.CharsetDecoder chardecoder,
java.nio.charset.CharsetEncoder charencoder,
org.apache.http.config.MessageConstraints constraints,
org.apache.http.entity.ContentLengthStrategy incomingContentStrategy,
org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy) |
Creates new instance NHttpConnectionBase given the underlying I/O session.
|
protected |
NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
java.nio.charset.CharsetDecoder chardecoder,
java.nio.charset.CharsetEncoder charencoder,
org.apache.http.entity.ContentLengthStrategy incomingContentStrategy,
org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy) |
Creates new instance NHttpConnectionBase given the underlying I/O session.
|
|
NHttpConnectionBase(IOSession session,
ByteBufferAllocator allocator,
org.apache.http.params.HttpParams params) |
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
assertNotClosed() |
Assets if the connection is still open.
|
protected void |
bind(IOSession session) |
Binds the connection to a different
IOSession. |
void |
close() |
|
protected org.apache.http.impl.HttpConnectionMetricsImpl |
createConnectionMetrics(org.apache.http.io.HttpTransportMetrics inTransportMetric,
org.apache.http.io.HttpTransportMetrics outTransportMetric) |
Deprecated.
(4.3) use decorator to add additional metrics.
|
protected ContentDecoder |
createContentDecoder(long len,
java.nio.channels.ReadableByteChannel channel,
SessionInputBuffer buffer,
org.apache.http.impl.io.HttpTransportMetricsImpl metrics) |
Factory method for
ContentDecoder instances. |
protected ContentEncoder |
createContentEncoder(long len,
java.nio.channels.WritableByteChannel channel,
SessionOutputBuffer buffer,
org.apache.http.impl.io.HttpTransportMetricsImpl metrics) |
Factory method for
ContentEncoder instances. |
protected org.apache.http.entity.ContentLengthStrategy |
createIncomingContentStrategy() |
Deprecated.
(4.3) use constructor.
|
protected org.apache.http.entity.ContentLengthStrategy |
createOutgoingContentStrategy() |
Deprecated.
(4.3) use constructor.
|
protected org.apache.http.impl.io.HttpTransportMetricsImpl |
createTransportMetrics() |
Deprecated.
(4.3) no longer used.
|
org.apache.http.protocol.HttpContext |
getContext() |
Returns an HTTP execution context associated with this connection.
|
org.apache.http.HttpRequest |
getHttpRequest() |
Returns the current HTTP request if one is being received / transmitted.
|
org.apache.http.HttpResponse |
getHttpResponse() |
Returns the current HTTP response if one is being received / transmitted.
|
java.net.InetAddress |
getLocalAddress() |
|
int |
getLocalPort() |
|
org.apache.http.HttpConnectionMetrics |
getMetrics() |
|
java.net.InetAddress |
getRemoteAddress() |
|
int |
getRemotePort() |
|
java.net.Socket |
getSocket() |
Return the underlying socket
|
int |
getSocketTimeout() |
|
int |
getStatus() |
Returns status of the connection:
|
boolean |
hasBufferedInput() |
Determines if the session input buffer contains data.
|
boolean |
hasBufferedOutput() |
Determines if the session output buffer contains data.
|
boolean |
isOpen() |
|
boolean |
isStale() |
|
protected org.apache.http.HttpEntity |
prepareDecoder(org.apache.http.HttpMessage message) |
Initializes a specific
ContentDecoder implementation based on the
properties of the given HttpMessage and generates an instance of
HttpEntity matching the properties of the content decoder. |
protected void |
prepareEncoder(org.apache.http.HttpMessage message) |
Initializes a specific
ContentEncoder implementation based on the
properties of the given HttpMessage. |
void |
requestInput() |
Requests event notifications to be triggered when the underlying
channel is ready for input operations.
|
void |
requestOutput() |
Requests event notifications to be triggered when the underlying
channel is ready for output operations.
|
void |
setSocketTimeout(int timeout) |
|
void |
shutdown() |
Shuts down the underlying channel.
|
void |
suspendInput() |
Suspends event notifications about the underlying channel being
ready for input operations.
|
void |
suspendOutput() |
Suspends event notifications about the underlying channel being
ready for output operations.
|
java.lang.String |
toString() |
protected final org.apache.http.entity.ContentLengthStrategy incomingContentStrategy
protected final org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy
protected final SessionInputBufferImpl inbuf
protected final SessionOutputBufferImpl outbuf
protected final org.apache.http.impl.io.HttpTransportMetricsImpl inTransportMetrics
protected final org.apache.http.impl.io.HttpTransportMetricsImpl outTransportMetrics
protected final org.apache.http.impl.HttpConnectionMetricsImpl connMetrics
protected org.apache.http.protocol.HttpContext context
protected IOSession session
protected java.net.SocketAddress remote
protected volatile ContentDecoder contentDecoder
protected volatile boolean hasBufferedInput
protected volatile ContentEncoder contentEncoder
protected volatile boolean hasBufferedOutput
protected volatile org.apache.http.HttpRequest request
protected volatile org.apache.http.HttpResponse response
protected volatile int status
@Deprecated public NHttpConnectionBase(IOSession session, ByteBufferAllocator allocator, org.apache.http.params.HttpParams params)
NHttpConnectionBase(IOSession, int, int, ByteBufferAllocator,
CharsetDecoder, CharsetEncoder, ContentLengthStrategy, ContentLengthStrategy)session - the underlying I/O session.allocator - byte buffer allocator.params - HTTP parameters.protected NHttpConnectionBase(IOSession session, int buffersize, int fragmentSizeHint, ByteBufferAllocator allocator, java.nio.charset.CharsetDecoder chardecoder, java.nio.charset.CharsetEncoder charencoder, org.apache.http.config.MessageConstraints constraints, org.apache.http.entity.ContentLengthStrategy incomingContentStrategy, org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy)
session - the underlying I/O session.buffersize - buffer size. Must be a positive number.fragmentSizeHint - fragment size hint.allocator - memory allocator.
If null HeapByteBufferAllocator.INSTANCE
will be used.chardecoder - decoder to be used for decoding HTTP protocol elements.
If null simple type cast will be used for byte to char conversion.charencoder - encoder to be used for encoding HTTP protocol elements.
If null simple type cast will be used for char to byte conversion.constraints - Message constraints. If null
MessageConstraints.DEFAULT will be used.incomingContentStrategy - incoming content length strategy. If null
LaxContentLengthStrategy.INSTANCE will be used.outgoingContentStrategy - outgoing content length strategy. If null
StrictContentLengthStrategy.INSTANCE will be used.protected NHttpConnectionBase(IOSession session, int buffersize, int fragmentSizeHint, ByteBufferAllocator allocator, java.nio.charset.CharsetDecoder chardecoder, java.nio.charset.CharsetEncoder charencoder, org.apache.http.entity.ContentLengthStrategy incomingContentStrategy, org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy)
session - the underlying I/O session.buffersize - buffer size. Must be a positive number.fragmentSizeHint - fragment size hint.allocator - memory allocator.
If null HeapByteBufferAllocator.INSTANCE
will be used.chardecoder - decoder to be used for decoding HTTP protocol elements.
If null simple type cast will be used for byte to char conversion.charencoder - encoder to be used for encoding HTTP protocol elements.
If null simple type cast will be used for char to byte conversion.incomingContentStrategy - incoming content length strategy. If null
LaxContentLengthStrategy.INSTANCE will be used.outgoingContentStrategy - outgoing content length strategy. If null
StrictContentLengthStrategy.INSTANCE will be used.protected void bind(IOSession session)
IOSession. This may be necessary
when the underlying I/O session gets upgraded with SSL/TLS encryption.@Deprecated protected org.apache.http.entity.ContentLengthStrategy createIncomingContentStrategy()
@Deprecated protected org.apache.http.entity.ContentLengthStrategy createOutgoingContentStrategy()
@Deprecated protected org.apache.http.impl.io.HttpTransportMetricsImpl createTransportMetrics()
@Deprecated
protected org.apache.http.impl.HttpConnectionMetricsImpl createConnectionMetrics(org.apache.http.io.HttpTransportMetrics inTransportMetric,
org.apache.http.io.HttpTransportMetrics outTransportMetric)
public int getStatus()
NHttpConnection
NHttpConnection.ACTIVE: connection is active.
NHttpConnection.CLOSING: connection is being closed.
NHttpConnection.CLOSED: connection has been closed.
getStatus in interface NHttpConnectionpublic org.apache.http.protocol.HttpContext getContext()
NHttpConnectiongetContext in interface NHttpConnectionpublic org.apache.http.HttpRequest getHttpRequest()
NHttpConnectionnull.getHttpRequest in interface NHttpConnectionnull otherwise.public org.apache.http.HttpResponse getHttpResponse()
NHttpConnectionnull.getHttpResponse in interface NHttpConnectionnull otherwise.public void requestInput()
IOControlrequestInput in interface IOControlpublic void requestOutput()
IOControlrequestOutput in interface IOControlpublic void suspendInput()
IOControlsuspendInput in interface IOControlpublic void suspendOutput()
IOControlsuspendOutput in interface IOControlprotected org.apache.http.HttpEntity prepareDecoder(org.apache.http.HttpMessage message)
throws org.apache.http.HttpException
ContentDecoder implementation based on the
properties of the given HttpMessage and generates an instance of
HttpEntity matching the properties of the content decoder.message - the HTTP message.org.apache.http.HttpException - in case of an HTTP protocol violation.protected ContentDecoder createContentDecoder(long len, java.nio.channels.ReadableByteChannel channel, SessionInputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics)
ContentDecoder instances.len - content length, if known, ContentLengthStrategy.CHUNKED or
ContentLengthStrategy.IDENTITY, if unknown.channel - the session channel.buffer - the session buffer.metrics - transport metrics.protected void prepareEncoder(org.apache.http.HttpMessage message)
throws org.apache.http.HttpException
ContentEncoder implementation based on the
properties of the given HttpMessage.message - the HTTP message.org.apache.http.HttpException - in case of an HTTP protocol violation.protected ContentEncoder createContentEncoder(long len, java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics)
ContentEncoder instances.len - content length, if known, ContentLengthStrategy.CHUNKED or
ContentLengthStrategy.IDENTITY, if unknown.channel - the session channel.buffer - the session buffer.metrics - transport metrics.public boolean hasBufferedInput()
SessionBufferStatushasBufferedInput in interface SessionBufferStatustrue if the session input buffer contains data,
false otherwise.public boolean hasBufferedOutput()
SessionBufferStatushasBufferedOutput in interface SessionBufferStatustrue if the session output buffer contains data,
false otherwise.protected void assertNotClosed()
throws org.apache.http.ConnectionClosedException
org.apache.http.ConnectionClosedException - in case the connection has already
been closed.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeableclose in interface org.apache.http.HttpConnectionjava.io.IOExceptionpublic boolean isOpen()
isOpen in interface org.apache.http.HttpConnectionpublic boolean isStale()
isStale in interface org.apache.http.HttpConnectionpublic java.net.InetAddress getLocalAddress()
getLocalAddress in interface org.apache.http.HttpInetConnectionpublic int getLocalPort()
getLocalPort in interface org.apache.http.HttpInetConnectionpublic java.net.InetAddress getRemoteAddress()
getRemoteAddress in interface org.apache.http.HttpInetConnectionpublic int getRemotePort()
getRemotePort in interface org.apache.http.HttpInetConnectionpublic void setSocketTimeout(int timeout)
setSocketTimeout in interface org.apache.http.HttpConnectionpublic int getSocketTimeout()
getSocketTimeout in interface org.apache.http.HttpConnectionpublic void shutdown()
throws java.io.IOException
IOControlpublic org.apache.http.HttpConnectionMetrics getMetrics()
getMetrics in interface org.apache.http.HttpConnectionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.net.Socket getSocket()
SocketAccessorgetSocket in interface SocketAccessornull.