Package org.apache.http.nio.reactor.ssl
Class SSLIOSession
java.lang.Object
org.apache.http.nio.reactor.ssl.SSLIOSession
- All Implemented Interfaces:
IOSession,SessionBufferStatus,SocketAccessor
- Direct Known Subclasses:
SSLIOSession
@Contract(threading=SAFE_CONDITIONAL)
public class SSLIOSession
extends Object
implements IOSession, SessionBufferStatus, SocketAccessor
SSLIOSession is a decorator class intended to transparently extend
an IOSession with transport layer security capabilities based on
the SSL/TLS protocol.
The resultant instance of SSLIOSession must be added to the original
I/O session as an attribute with the SESSION_KEY key.
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, null, null);
SSLIOSession sslsession = new SSLIOSession(
iosession, SSLMode.CLIENT, sslContext, null);
iosession.setAttribute(SSLIOSession.SESSION_KEY, sslsession);
- Since:
- 4.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the context attribute key, which can be used to obtain the SSL session.Fields inherited from interface org.apache.http.nio.reactor.IOSession
ACTIVE, ATTACHMENT_KEY, CLOSED, CLOSING -
Constructor Summary
ConstructorsConstructorDescriptionSSLIOSession(IOSession session, SSLMode sslMode, SSLContext sslContext, SSLSetupHandler handler) Creates new instance ofSSLIOSessionclass.SSLIOSession(IOSession session, SSLMode sslMode, HttpHost host, SSLContext sslContext, SSLSetupHandler handler) Creates new instance ofSSLIOSessionclass.SSLIOSession(IOSession session, SSLMode sslMode, HttpHost host, SSLContext sslContext, SSLSetupHandler handler, SSLBufferManagementStrategy bufferManagementStrategy) Creates new instance ofSSLIOSessionclass. -
Method Summary
Modifier and TypeMethodDescriptionchannel()Returns the underlying I/O channel associated with this session.voidclearEvent(int op) Clears interest in a particular I/O event type by updating the event mask associated with the session.voidclose()Terminates the session gracefully and closes the underlying I/O channel.getAttribute(String name) Returns the value of the attribute with the given name.intReturns mask of I/O evens this session declared interest in.Returns local address.Returns address of the remote peer.Return the underlying socketintReturns value of the socket timeout in milliseconds.intReturns status of the session:booleanDetermines if the input buffer associated with the session contains data.booleanDetermines if the output buffer associated with the session contains data.voidExecutes inbound SSL transport operations.voidInitializes the session.voidinitialize(SSLMode sslMode) Deprecated.(4.3) SSL mode must be set at construction time.booleanReads encrypted data and returns whether the channel associated with this session has any decrypted inbound data available for reading.booleanReturns whether the channel associated with this session is ready to accept outbound unecrypted data for writing.booleanisClosed()Determines if the session has been terminated.booleanReturns whether the session will produce any more inbound data.booleanReturnstrueis the session has been fully initialized,falseotherwise.booleanReturns whether the session will accept any more outbound data.voidSends encrypted data and executes outbound SSL transport operations.removeAttribute(String name) Removes attribute with the given name.voidsetAttribute(String name, Object obj) This method can be used to associate a particular object with the session by the given attribute name.voidsetBufferStatus(SessionBufferStatus status) Quite often I/O sessions need to maintain internal I/O buffers in order to transform input / output data prior to returning it to the consumer or writing it to the underlying channel.voidsetEvent(int op) Declares interest in a particular I/O event type by updating the event mask associated with the session.voidsetEventMask(int ops) Declares interest in I/O event notifications by setting the event mask associated with the sessionvoidsetSocketTimeout(int timeout) Sets value of the socket timeout in milliseconds.voidshutdown()Terminates the session by shutting down the underlying I/O channel.toString()
-
Field Details
-
SESSION_KEY
Name of the context attribute key, which can be used to obtain the SSL session.- See Also:
-
-
Constructor Details
-
SSLIOSession
public SSLIOSession(IOSession session, SSLMode sslMode, HttpHost host, SSLContext sslContext, SSLSetupHandler handler) Creates new instance ofSSLIOSessionclass. The instances created uses aPermanentSSLBufferManagementStrategyto manage its buffers.- Parameters:
session- I/O session to be decorated with the TLS/SSL capabilities.sslMode- SSL mode (client or server)host- original host (applicable in client mode only)sslContext- SSL context to use for this I/O session.handler- optional SSL setup handler. May benull.- Since:
- 4.4
-
SSLIOSession
public SSLIOSession(IOSession session, SSLMode sslMode, HttpHost host, SSLContext sslContext, SSLSetupHandler handler, SSLBufferManagementStrategy bufferManagementStrategy) Creates new instance ofSSLIOSessionclass.- Parameters:
session- I/O session to be decorated with the TLS/SSL capabilities.sslMode- SSL mode (client or server)host- original host (applicable in client mode only)sslContext- SSL context to use for this I/O session.handler- optional SSL setup handler. May benull.bufferManagementStrategy- buffer management strategy
-
SSLIOSession
public SSLIOSession(IOSession session, SSLMode sslMode, SSLContext sslContext, SSLSetupHandler handler) Creates new instance ofSSLIOSessionclass.- Parameters:
session- I/O session to be decorated with the TLS/SSL capabilities.sslMode- SSL mode (client or server)sslContext- SSL context to use for this I/O session.handler- optional SSL setup handler. May benull.
-
-
Method Details
-
isInitialized
public boolean isInitialized()Returnstrueis the session has been fully initialized,falseotherwise. -
initialize
Deprecated.(4.3) SSL mode must be set at construction time.Initializes the session in the givenSSLMode. This method invokes theSSLSetupHandler.initalize(SSLEngine)callback if an instance ofSSLSetupHandlerwas specified at the construction time.- Throws:
SSLException
-
initialize
Initializes the session. This method invokes theSSLSetupHandler.initalize(SSLEngine)callback if an instance ofSSLSetupHandlerwas specified at the construction time.- Throws:
SSLException- in case of a SSL protocol exception.IllegalStateException- if the session has already been initialized.
-
getSSLSession
-
isAppInputReady
Reads encrypted data and returns whether the channel associated with this session has any decrypted inbound data available for reading.- Throws:
IOException- in case of an I/O error.
-
isAppOutputReady
Returns whether the channel associated with this session is ready to accept outbound unecrypted data for writing.- Throws:
IOException- - not thrown currently
-
inboundTransport
Executes inbound SSL transport operations.- Throws:
IOException- - not thrown currently
-
outboundTransport
Sends encrypted data and executes outbound SSL transport operations.- Throws:
IOException- in case of an I/O error.
-
isInboundDone
public boolean isInboundDone()Returns whether the session will produce any more inbound data. -
isOutboundDone
public boolean isOutboundDone()Returns whether the session will accept any more outbound data. -
close
public void close()Description copied from interface:IOSessionTerminates the session gracefully and closes the underlying I/O channel. This method ensures that session termination handshake, such as the one used by the SSL/TLS protocol, is correctly carried out. -
shutdown
public void shutdown()Description copied from interface:IOSessionTerminates the session by shutting down the underlying I/O channel. -
getStatus
public int getStatus()Description copied from interface:IOSessionReturns status of the session:IOSession.ACTIVE: session is active.IOSession.CLOSING: session is being closed.IOSession.CLOSED: session has been terminated. -
isClosed
public boolean isClosed()Description copied from interface:IOSessionDetermines if the session has been terminated. -
channel
Description copied from interface:IOSessionReturns the underlying I/O channel associated with this session. -
getLocalAddress
Description copied from interface:IOSessionReturns local address.- Specified by:
getLocalAddressin interfaceIOSession- Returns:
- socket address.
-
getRemoteAddress
Description copied from interface:IOSessionReturns address of the remote peer.- Specified by:
getRemoteAddressin interfaceIOSession- Returns:
- socket address.
-
getEventMask
public int getEventMask()Description copied from interface:IOSessionReturns mask of I/O evens this session declared interest in.- Specified by:
getEventMaskin interfaceIOSession- Returns:
- I/O event mask.
-
setEventMask
public void setEventMask(int ops) Description copied from interface:IOSessionDeclares interest in I/O event notifications by setting the event mask associated with the session- Specified by:
setEventMaskin interfaceIOSession- Parameters:
ops- new I/O event mask.
-
setEvent
public void setEvent(int op) Description copied from interface:IOSessionDeclares interest in a particular I/O event type by updating the event mask associated with the session. -
clearEvent
public void clearEvent(int op) Description copied from interface:IOSessionClears interest in a particular I/O event type by updating the event mask associated with the session.- Specified by:
clearEventin interfaceIOSession- Parameters:
op- I/O event type.
-
getSocketTimeout
public int getSocketTimeout()Description copied from interface:IOSessionReturns value of the socket timeout in milliseconds. The value of0signifies the session cannot time out.- Specified by:
getSocketTimeoutin interfaceIOSession- Returns:
- socket timeout.
-
setSocketTimeout
public void setSocketTimeout(int timeout) Description copied from interface:IOSessionSets value of the socket timeout in milliseconds. The value of0signifies the session cannot time out.- Specified by:
setSocketTimeoutin interfaceIOSession- Parameters:
timeout- socket timeout.
-
hasBufferedInput
public boolean hasBufferedInput()Description copied from interface:IOSessionDetermines if the input buffer associated with the session contains data.- Specified by:
hasBufferedInputin interfaceIOSession- Specified by:
hasBufferedInputin interfaceSessionBufferStatus- Returns:
trueif the session input buffer contains data,falseotherwise.
-
hasBufferedOutput
public boolean hasBufferedOutput()Description copied from interface:IOSessionDetermines if the output buffer associated with the session contains data.- Specified by:
hasBufferedOutputin interfaceIOSession- Specified by:
hasBufferedOutputin interfaceSessionBufferStatus- Returns:
trueif the session output buffer contains data,falseotherwise.
-
setBufferStatus
Description copied from interface:IOSessionQuite often I/O sessions need to maintain internal I/O buffers in order to transform input / output data prior to returning it to the consumer or writing it to the underlying channel. Memory management in HttpCore NIO is based on the fundamental principle that the data consumer can read only as much input data as it can process without having to allocate more memory. That means, quite often some input data may remain unread in one of the internal or external session buffers. The I/O reactor can query the status of these session buffers, and make sure the consumer gets notified correctly as more data gets stored in one of the session buffers, thus allowing the consumer to read the remaining data once it is able to process itI/O sessions can be made aware of the status of external session buffers using the
SessionBufferStatusinterface.- Specified by:
setBufferStatusin interfaceIOSession
-
getAttribute
Description copied from interface:IOSessionReturns the value of the attribute with the given name. The value can benullif not set.The value of the session attachment object can be obtained using
IOSession.ATTACHMENT_KEYname.- Specified by:
getAttributein interfaceIOSession- Parameters:
name- name of the attribute.- Returns:
- value of the attribute.
- See Also:
-
removeAttribute
Description copied from interface:IOSessionRemoves attribute with the given name.- Specified by:
removeAttributein interfaceIOSession- Parameters:
name- name of the attribute to be removed.- Returns:
- value of the removed attribute.
- See Also:
-
setAttribute
Description copied from interface:IOSessionThis method can be used to associate a particular object with the session by the given attribute name.I/O sessions are not bound to an execution thread, therefore one cannot use the context of the thread to store a session's state. All details about a particular session must be stored within the session itself.
- Specified by:
setAttributein interfaceIOSession- Parameters:
name- name of the attribute.obj- value of the attribute.
-
toString
-
getSocket
Description copied from interface:SocketAccessorReturn the underlying socket- Specified by:
getSocketin interfaceSocketAccessor- Returns:
- - the underlying Socket, may be
null.
-