Package org.apache.hc.core5.http.impl.io
Class DefaultBHttpClientConnection
- java.lang.Object
-
- org.apache.hc.core5.http.impl.io.BHttpConnectionBase
-
- org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,HttpConnection
,BHttpConnection
,HttpClientConnection
,SocketModalCloseable
,ModalCloseable
- Direct Known Subclasses:
LoggingBHttpClientConnection
public class DefaultBHttpClientConnection extends BHttpConnectionBase implements HttpClientConnection
Default implementation ofHttpClientConnection
.- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
consistent
private ContentLengthStrategy
incomingContentStrategy
private ContentLengthStrategy
outgoingContentStrategy
private HttpMessageWriter<ClassicHttpRequest>
requestWriter
private ResponseOutOfOrderStrategy
responseOutOfOrderStrategy
private HttpMessageParser<ClassicHttpResponse>
responseParser
-
Fields inherited from class org.apache.hc.core5.http.impl.io.BHttpConnectionBase
connMetrics, endpointDetails, http1Config, inBuffer, outbuffer, socketHolderRef, version
-
-
Constructor Summary
Constructors Constructor Description DefaultBHttpClientConnection(Http1Config http1Config)
DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory, HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory)
Creates new instance of DefaultBHttpClientConnection.DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, ResponseOutOfOrderStrategy responseOutOfOrderStrategy, HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory, HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory)
Creates new instance of DefaultBHttpClientConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(java.net.Socket socket)
Binds this connection to the givenSocket
.boolean
isConsistent()
Checks whether this connection is in a consistent state.protected void
onRequestSubmitted(ClassicHttpRequest request)
protected void
onResponseReceived(ClassicHttpResponse response)
void
receiveResponseEntity(ClassicHttpResponse response)
Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.ClassicHttpResponse
receiveResponseHeader()
Receives the request line and headers of the next response available from this connection.void
sendRequestEntity(ClassicHttpRequest request)
Sends the request entity over the connection.void
sendRequestHeader(ClassicHttpRequest request)
Sends the request line and all headers over the connection.void
terminateRequest(ClassicHttpRequest request)
Terminates request prematurely potentially leaving the connection in a inconsistent state.-
Methods inherited from class org.apache.hc.core5.http.impl.io.BHttpConnectionBase
awaitInput, bind, close, close, createContentInputStream, createContentOutputStream, createIncomingEntity, ensureOpen, flush, getEndpointDetails, getLocalAddress, getProtocolVersion, getRemoteAddress, getSocketHolder, getSocketTimeout, getSSLSession, incrementRequestCount, incrementResponseCount, isDataAvailable, isOpen, isStale, setSocketTimeout, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.hc.core5.http.io.BHttpConnection
flush, isDataAvailable, isStale
-
Methods inherited from interface org.apache.hc.core5.http.HttpConnection
close, getEndpointDetails, getLocalAddress, getProtocolVersion, getRemoteAddress, getSSLSession, isOpen
-
Methods inherited from interface org.apache.hc.core5.io.ModalCloseable
close
-
Methods inherited from interface org.apache.hc.core5.http.SocketModalCloseable
getSocketTimeout, setSocketTimeout
-
-
-
-
Field Detail
-
responseParser
private final HttpMessageParser<ClassicHttpResponse> responseParser
-
requestWriter
private final HttpMessageWriter<ClassicHttpRequest> requestWriter
-
incomingContentStrategy
private final ContentLengthStrategy incomingContentStrategy
-
outgoingContentStrategy
private final ContentLengthStrategy outgoingContentStrategy
-
responseOutOfOrderStrategy
private final ResponseOutOfOrderStrategy responseOutOfOrderStrategy
-
consistent
private volatile boolean consistent
-
-
Constructor Detail
-
DefaultBHttpClientConnection
public DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, ResponseOutOfOrderStrategy responseOutOfOrderStrategy, HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory, HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory)
Creates new instance of DefaultBHttpClientConnection.- Parameters:
http1Config
- Message http1Config. Ifnull
Http1Config.DEFAULT
will be used.charDecoder
- decoder to be used for decoding HTTP protocol elements. Ifnull
simple type cast will be used for byte to char conversion.charEncoder
- encoder to be used for encoding HTTP protocol elements. Ifnull
simple type cast will be used for char to byte conversion.incomingContentStrategy
- incoming content length strategy. Ifnull
DefaultContentLengthStrategy.INSTANCE
will be used.outgoingContentStrategy
- outgoing content length strategy. Ifnull
DefaultContentLengthStrategy.INSTANCE
will be used.responseOutOfOrderStrategy
- response out of order strategy. Ifnull
NoResponseOutOfOrderStrategy.INSTANCE
will be used.requestWriterFactory
- request writer factory. Ifnull
DefaultHttpRequestWriterFactory.INSTANCE
will be used.responseParserFactory
- response parser factory. Ifnull
DefaultHttpResponseParserFactory.INSTANCE
will be used.
-
DefaultBHttpClientConnection
public DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory, HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory)
Creates new instance of DefaultBHttpClientConnection.- Parameters:
http1Config
- Message http1Config. Ifnull
Http1Config.DEFAULT
will be used.charDecoder
- decoder to be used for decoding HTTP protocol elements. Ifnull
simple type cast will be used for byte to char conversion.charEncoder
- encoder to be used for encoding HTTP protocol elements. Ifnull
simple type cast will be used for char to byte conversion.incomingContentStrategy
- incoming content length strategy. Ifnull
DefaultContentLengthStrategy.INSTANCE
will be used.outgoingContentStrategy
- outgoing content length strategy. Ifnull
DefaultContentLengthStrategy.INSTANCE
will be used.requestWriterFactory
- request writer factory. Ifnull
DefaultHttpRequestWriterFactory.INSTANCE
will be used.responseParserFactory
- response parser factory. Ifnull
DefaultHttpResponseParserFactory.INSTANCE
will be used.
-
DefaultBHttpClientConnection
public DefaultBHttpClientConnection(Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
-
DefaultBHttpClientConnection
public DefaultBHttpClientConnection(Http1Config http1Config)
-
-
Method Detail
-
onResponseReceived
protected void onResponseReceived(ClassicHttpResponse response)
-
onRequestSubmitted
protected void onRequestSubmitted(ClassicHttpRequest request)
-
bind
public void bind(java.net.Socket socket) throws java.io.IOException
Description copied from class:BHttpConnectionBase
Binds this connection to the givenSocket
. This socket will be used by the connection to send and receive data.After this method's execution the connection status will be reported as open and the
BHttpConnectionBase.isOpen()
will returntrue
.- Overrides:
bind
in classBHttpConnectionBase
- Parameters:
socket
- the socket.- Throws:
java.io.IOException
- in case of an I/O error.
-
sendRequestHeader
public void sendRequestHeader(ClassicHttpRequest request) throws HttpException, java.io.IOException
Description copied from interface:HttpClientConnection
Sends the request line and all headers over the connection.- Specified by:
sendRequestHeader
in interfaceHttpClientConnection
- Parameters:
request
- the request whose headers to send.- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
sendRequestEntity
public void sendRequestEntity(ClassicHttpRequest request) throws HttpException, java.io.IOException
Description copied from interface:HttpClientConnection
Sends the request entity over the connection.- Specified by:
sendRequestEntity
in interfaceHttpClientConnection
- Parameters:
request
- the request whose entity to send.- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
isConsistent
public boolean isConsistent()
Description copied from interface:HttpClientConnection
Checks whether this connection is in a consistent state.- Specified by:
isConsistent
in interfaceHttpClientConnection
- Returns:
true
if the connection is known to be in a inconsistent state and cannot be re-used.- See Also:
HttpClientConnection.terminateRequest(ClassicHttpRequest)
-
terminateRequest
public void terminateRequest(ClassicHttpRequest request) throws HttpException, java.io.IOException
Description copied from interface:HttpClientConnection
Terminates request prematurely potentially leaving the connection in a inconsistent state.- Specified by:
terminateRequest
in interfaceHttpClientConnection
- Parameters:
request
- the request to be terminated prematurely.- Throws:
HttpException
java.io.IOException
- See Also:
HttpClientConnection.isConsistent()
-
receiveResponseHeader
public ClassicHttpResponse receiveResponseHeader() throws HttpException, java.io.IOException
Description copied from interface:HttpClientConnection
Receives the request line and headers of the next response available from this connection. The caller should examine the HttpResponse object to find out if it should try to receive a response entity as well.- Specified by:
receiveResponseHeader
in interfaceHttpClientConnection
- Returns:
- a new HttpResponse object with status line and headers
initialized or
null
if the connection has been closed by the opposite endpoint. - Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
receiveResponseEntity
public void receiveResponseEntity(ClassicHttpResponse response) throws HttpException, java.io.IOException
Description copied from interface:HttpClientConnection
Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.- Specified by:
receiveResponseEntity
in interfaceHttpClientConnection
- Parameters:
response
- the response to attach the entity to- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
-