Class LoggingBHttpServerConnection
java.lang.Object
org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection
org.apache.hc.core5.testing.classic.LoggingBHttpServerConnection
- All Implemented Interfaces:
Closeable,AutoCloseable,HttpConnection,BHttpConnection,HttpServerConnection,SocketModalCloseable,ModalCloseable,Identifiable
public class LoggingBHttpServerConnection
extends DefaultBHttpServerConnection
implements Identifiable
-
Constructor Summary
ConstructorsConstructorDescriptionLoggingBHttpServerConnection(String scheme, Http1Config http1Config) LoggingBHttpServerConnection(String scheme, Http1Config http1Config, CharsetDecoder charDecoder, CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory, HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanawaitInput(Timeout timeout) voidBinds this connection to the givenSocket.protected voidbind(SocketHolder socketHolder) voidclose()Closes this connection gracefully.voidCloses this process or endpoint and releases any system resources associated with it.protected InputStreamcreateContentInputStream(long len, SessionInputBuffer buffer, InputStream inputStream) protected OutputStreamcreateContentOutputStream(long len, SessionOutputBuffer buffer, OutputStream outputStream, Supplier<List<? extends Header>> trailers) protected SocketHoldervoidflush()Writes out all pending buffered data over the open connection.Returns this connection's endpoint details.getId()Returns this connection's local address ornullif it is not bound yet.Returns this connection's protocol version ornullif unknown.Returns this connection's remote address ornullif it is not connected yet or unconnected.protected SocketHolderReturns the socket timeout value.Returns this connection's SSL session ornullif TLS has not been activated.protected voidprotected voidbooleanisDataAvailable(Timeout timeout) Checks if input data is available from the connection.booleanisOpen()Checks if this connection is open.booleanisStale()Checks whether this connection has gone down.protected voidonRequestReceived(ClassicHttpRequest request) protected voidonResponseSubmitted(ClassicHttpResponse response) voidsetSocketTimeout(Timeout timeout) Sets the socket timeout value.toString()Methods inherited from class org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection
receiveRequestEntity, receiveRequestHeader, sendResponseEntity, sendResponseHeaderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hc.core5.http.io.BHttpConnection
flush, isDataAvailable, isStaleMethods inherited from interface org.apache.hc.core5.http.HttpConnection
getEndpointDetails, getLocalAddress, getProtocolVersion, getRemoteAddress, getSSLSession, isOpenMethods inherited from interface org.apache.hc.core5.http.SocketModalCloseable
getSocketTimeout, setSocketTimeout
-
Constructor Details
-
LoggingBHttpServerConnection
public LoggingBHttpServerConnection(String scheme, Http1Config http1Config, CharsetDecoder charDecoder, CharsetEncoder charEncoder, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory, HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) -
LoggingBHttpServerConnection
-
-
Method Details
-
getId
- Specified by:
getIdin interfaceIdentifiable
-
close
Description copied from interface:HttpConnectionCloses this connection gracefully. This method will attempt to flush the internal output buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Useshutdowninstead.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceHttpConnection- Throws:
IOException
-
close
Description copied from interface:ModalCloseableCloses this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.- Specified by:
closein interfaceModalCloseable- Parameters:
closeMode- How to close the receiver.
-
bind
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
HttpConnection.isOpen()will returntrue.- Overrides:
bindin classDefaultBHttpServerConnection- Parameters:
socket- the socket.- Throws:
IOException- in case of an I/O error.
-
onRequestReceived
- Overrides:
onRequestReceivedin classDefaultBHttpServerConnection
-
onResponseSubmitted
- Overrides:
onResponseSubmittedin classDefaultBHttpServerConnection
-
ensureOpen
- Throws:
IOException
-
bind
- Throws:
IOException
-
isOpen
public boolean isOpen()Description copied from interface:HttpConnectionChecks if this connection is open.- Specified by:
isOpenin interfaceHttpConnection- Returns:
- true if it is open, false if it is closed.
-
getProtocolVersion
Description copied from interface:HttpConnectionReturns this connection's protocol version ornullif unknown.- Specified by:
getProtocolVersionin interfaceHttpConnection- Returns:
- this connection's protocol version or
nullif unknown. - Since:
- 5.0
-
getSocketHolder
-
createContentOutputStream
protected OutputStream createContentOutputStream(long len, SessionOutputBuffer buffer, OutputStream outputStream, Supplier<List<? extends Header>> trailers) -
createContentInputStream
protected InputStream createContentInputStream(long len, SessionInputBuffer buffer, InputStream inputStream) -
getRemoteAddress
Description copied from interface:HttpConnectionReturns this connection's remote address ornullif it is not connected yet or unconnected.- Specified by:
getRemoteAddressin interfaceHttpConnection- Returns:
- this connection's remote address or
nullif it is not connected yet or unconnected.
-
getLocalAddress
Description copied from interface:HttpConnectionReturns this connection's local address ornullif it is not bound yet.- Specified by:
getLocalAddressin interfaceHttpConnection- Returns:
- this connection's local address or
nullif it is not bound yet.
-
setSocketTimeout
Description copied from interface:SocketModalCloseableSets the socket timeout value.- Specified by:
setSocketTimeoutin interfaceSocketModalCloseable- Parameters:
timeout- timeout value
-
getSocketTimeout
Description copied from interface:SocketModalCloseableReturns the socket timeout value.- Specified by:
getSocketTimeoutin interfaceSocketModalCloseable- Returns:
- timeout value.
-
awaitInput
- Throws:
IOException
-
isDataAvailable
Description copied from interface:BHttpConnectionChecks if input data is available from the connection. May wait for the specified time until some data becomes available. Note that some implementations may completely ignore the timeout parameter.- Specified by:
isDataAvailablein interfaceBHttpConnection- Parameters:
timeout- the maximum time to wait for data- Returns:
- true if data is available; false if there was no data available
even after waiting for
timeout. - Throws:
IOException- if an error happens on the connection
-
isStale
Description copied from interface:BHttpConnectionChecks whether this connection has gone down. Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.- Specified by:
isStalein interfaceBHttpConnection- Returns:
trueif attempts to use this connection are likely to fail and this connection should be closed, orfalseif they are likely to succeed- Throws:
IOException
-
flush
Description copied from interface:BHttpConnectionWrites out all pending buffered data over the open connection.- Specified by:
flushin interfaceBHttpConnection- Throws:
IOException- in case of an I/O error
-
incrementRequestCount
protected void incrementRequestCount() -
incrementResponseCount
protected void incrementResponseCount() -
getSSLSession
Description copied from interface:HttpConnectionReturns this connection's SSL session ornullif TLS has not been activated.- Specified by:
getSSLSessionin interfaceHttpConnection- Returns:
- this connection's SSL session or
nullif TLS has not been activated.
-
getEndpointDetails
Description copied from interface:HttpConnectionReturns this connection's endpoint details.- Specified by:
getEndpointDetailsin interfaceHttpConnection- Returns:
- this connection's endpoint details.
-
toString
-