Package org.apache.hc.core5.http.impl.io
Class DefaultBHttpServerConnection
- java.lang.Object
-
- org.apache.hc.core5.http.impl.io.BHttpConnectionBase
-
- org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,HttpConnection
,BHttpConnection
,HttpServerConnection
,SocketModalCloseable
,ModalCloseable
- Direct Known Subclasses:
LoggingBHttpServerConnection
public class DefaultBHttpServerConnection extends BHttpConnectionBase implements HttpServerConnection
Default implementation ofHttpServerConnection
.- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description private ContentLengthStrategy
incomingContentStrategy
private ContentLengthStrategy
outgoingContentStrategy
private HttpMessageParser<ClassicHttpRequest>
requestParser
private HttpMessageWriter<ClassicHttpResponse>
responseWriter
private java.lang.String
scheme
-
Fields inherited from class org.apache.hc.core5.http.impl.io.BHttpConnectionBase
connMetrics, endpointDetails, http1Config, inBuffer, outbuffer, socketHolderRef, version
-
-
Constructor Summary
Constructors Constructor Description DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config)
DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory, HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory)
Creates new instance of DefaultBHttpServerConnection.
-
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
.protected void
onRequestReceived(ClassicHttpRequest request)
protected void
onResponseSubmitted(ClassicHttpResponse response)
void
receiveRequestEntity(ClassicHttpRequest request)
Receives the next request entity available from this connection and attaches it to an existing request.ClassicHttpRequest
receiveRequestHeader()
Receives the request line and all headers available from this connection.void
sendResponseEntity(ClassicHttpResponse response)
Sends the response entity of a response over this connection.void
sendResponseHeader(ClassicHttpResponse response)
Sends the response line and headers of a response over this connection.-
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
-
scheme
private final java.lang.String scheme
-
incomingContentStrategy
private final ContentLengthStrategy incomingContentStrategy
-
outgoingContentStrategy
private final ContentLengthStrategy outgoingContentStrategy
-
requestParser
private final HttpMessageParser<ClassicHttpRequest> requestParser
-
responseWriter
private final HttpMessageWriter<ClassicHttpResponse> responseWriter
-
-
Constructor Detail
-
DefaultBHttpServerConnection
public DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory, HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory)
Creates new instance of DefaultBHttpServerConnection.- Parameters:
scheme
- protocol schemehttp1Config
- 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.requestParserFactory
- request parser factory. Ifnull
DefaultHttpRequestParserFactory.INSTANCE
will be used.responseWriterFactory
- response writer factory. Ifnull
DefaultHttpResponseWriterFactory.INSTANCE
will be used.
-
DefaultBHttpServerConnection
public DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config, java.nio.charset.CharsetDecoder charDecoder, java.nio.charset.CharsetEncoder charEncoder)
-
DefaultBHttpServerConnection
public DefaultBHttpServerConnection(java.lang.String scheme, Http1Config http1Config)
-
-
Method Detail
-
onRequestReceived
protected void onRequestReceived(ClassicHttpRequest request)
-
onResponseSubmitted
protected void onResponseSubmitted(ClassicHttpResponse response)
-
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.
-
receiveRequestHeader
public ClassicHttpRequest receiveRequestHeader() throws HttpException, java.io.IOException
Description copied from interface:HttpServerConnection
Receives the request line and all headers available from this connection. The caller should examine the returned request and decide if to receive a request entity as well.- Specified by:
receiveRequestHeader
in interfaceHttpServerConnection
- Returns:
- a new HttpRequest object whose request line and headers are
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
-
receiveRequestEntity
public void receiveRequestEntity(ClassicHttpRequest request) throws HttpException, java.io.IOException
Description copied from interface:HttpServerConnection
Receives the next request entity available from this connection and attaches it to an existing request.- Specified by:
receiveRequestEntity
in interfaceHttpServerConnection
- Parameters:
request
- the request to attach the entity to.- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
sendResponseHeader
public void sendResponseHeader(ClassicHttpResponse response) throws HttpException, java.io.IOException
Description copied from interface:HttpServerConnection
Sends the response line and headers of a response over this connection.- Specified by:
sendResponseHeader
in interfaceHttpServerConnection
- Parameters:
response
- the response whose headers to send.- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
sendResponseEntity
public void sendResponseEntity(ClassicHttpResponse response) throws HttpException, java.io.IOException
Description copied from interface:HttpServerConnection
Sends the response entity of a response over this connection.- Specified by:
sendResponseEntity
in interfaceHttpServerConnection
- Parameters:
response
- the response whose entity to send.- Throws:
HttpException
- in case of HTTP protocol violationjava.io.IOException
- in case of an I/O error
-
-