Package org.apache.tomcat.websocket
Class WsSession
- java.lang.Object
- 
- org.apache.tomcat.websocket.WsSession
 
- 
- 
Constructor SummaryConstructors Constructor Description WsSession(Endpoint localEndpoint, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.net.URI requestUri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap, java.lang.String queryString, java.security.Principal userPrincipal, java.lang.String httpSessionId, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, EndpointConfig endpointConfig)Deprecated.Unused.WsSession(ClientEndpointHolder clientEndpointHolder, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, ClientEndpointConfig clientEndpointConfig)Creates a new WebSocket session for communication between the provided client and remote end points.WsSession(WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.net.URI requestUri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap, java.lang.String queryString, java.security.Principal userPrincipal, java.lang.String httpSessionId, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, ServerEndpointConfig serverEndpointConfig)Creates a new WebSocket session for communication between the provided server and remote end points.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidaddMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler)Registers aMessageHandlerfor partial incoming messages.<T> voidaddMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler)Registers aMessageHandlerfor whole incoming messages.voidaddMessageHandler(MessageHandler listener)Registers aMessageHandlerfor incoming messages.protected static voidappendCloseReasonWithTruncation(java.nio.ByteBuffer msg, java.lang.String reason)Use protected so unit tests can access this method directly.protected voidcheckExpiration()voidclose()Close the connection to the remote end point using the codeCloseReason.CloseCodes.NORMAL_CLOSUREand an empty reason phrase.voidclose(CloseReason closeReason)Close the connection to the remote end point using the specified code and reason phrase.voiddoClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal)WebSocket 1.0.voiddoClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal, boolean closeSocket)WebSocket 1.0.RemoteEndpoint.AsyncgetAsyncRemote()RemoteEndpoint.BasicgetBasicRemote()protected MessageHandlergetBinaryMessageHandler()WebSocketContainergetContainer()Get the container that created this session.java.lang.StringgetHttpSessionId()java.lang.StringgetId()Provides a unique identifier for the session.InstanceManagergetInstanceManager()EndpointgetLocal()intgetMaxBinaryMessageBufferSize()Get the current maximum buffer size for binary messages.longgetMaxIdleTimeout()Get the idle timeout for this session.intgetMaxTextMessageBufferSize()Get the maximum buffer size for text messages.java.util.Set<MessageHandler>getMessageHandlers()java.util.List<Extension>getNegotiatedExtensions()java.lang.StringgetNegotiatedSubprotocol()java.util.Set<Session>getOpenSessions()Obtain the set of open sessions associated with the same local endpoint as this session.java.util.Map<java.lang.String,java.lang.String>getPathParameters()protected MessageHandler.Whole<PongMessage>getPongMessageHandler()java.lang.StringgetProtocolVersion()java.lang.StringgetQueryString()java.util.Map<java.lang.String,java.util.List<java.lang.String>>getRequestParameterMap()java.net.URIgetRequestURI()protected MessageHandlergetTextMessageHandler()java.security.PrincipalgetUserPrincipal()java.util.Map<java.lang.String,java.lang.Object>getUserProperties()booleanisClosed()booleanisOpen()booleanisSecure()voidonClose(CloseReason closeReason)Called when a close message is received.protected voidregisterFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)Make the session aware of aFutureToSendHandlerthat will need to be forcibly closed if the session closes before theFutureToSendHandlercompletes.voidremoveMessageHandler(MessageHandler listener)voidresume()Resumes the reading of the incoming messages.voidsetMaxBinaryMessageBufferSize(int max)Set the current maximum buffer size for binary messages.voidsetMaxIdleTimeout(long timeout)Set the idle timeout for this session.voidsetMaxTextMessageBufferSize(int max)Set the maximum buffer size for text messages.voidsuspend()Suspends the reading of the incoming messages.protected voidunregisterFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)Remove aFutureToSendHandlerfrom the set of tracked instances.protected voidupdateLastActiveRead()protected voidupdateLastActiveWrite()
 
- 
- 
- 
Constructor Detail- 
WsSessionpublic WsSession(ClientEndpointHolder clientEndpointHolder, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, ClientEndpointConfig clientEndpointConfig) throws DeploymentException Creates a new WebSocket session for communication between the provided client and remote end points. The result ofThread.getContextClassLoader()at the time this constructor is called will be used when callingEndpoint.onClose(Session, CloseReason).- Parameters:
- clientEndpointHolder- The end point managed by this code
- wsRemoteEndpoint- The other / remote end point
- wsWebSocketContainer- The container that created this session
- negotiatedExtensions- The agreed extensions to use for this session
- subProtocol- The agreed sub-protocol to use for this session
- pathParameters- The path parameters associated with the request that initiated this session or- nullif this is a client session
- secure- Was this session initiated over a secure connection?
- clientEndpointConfig- The configuration information for the client end point
- Throws:
- DeploymentException- if an invalid encode is specified
 
 - 
WsSessionpublic WsSession(WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.net.URI requestUri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap, java.lang.String queryString, java.security.Principal userPrincipal, java.lang.String httpSessionId, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, ServerEndpointConfig serverEndpointConfig) throws DeploymentException Creates a new WebSocket session for communication between the provided server and remote end points. The result ofThread.getContextClassLoader()at the time this constructor is called will be used when callingEndpoint.onClose(Session, CloseReason).- Parameters:
- wsRemoteEndpoint- The other / remote end point
- wsWebSocketContainer- The container that created this session
- requestUri- The URI used to connect to this end point or- nullif this is a client session
- requestParameterMap- The parameters associated with the request that initiated this session or- nullif this is a client session
- queryString- The query string associated with the request that initiated this session or- nullif this is a client session
- userPrincipal- The principal associated with the request that initiated this session or- nullif this is a client session
- httpSessionId- The HTTP session ID associated with the request that initiated this session or- nullif this is a client session
- negotiatedExtensions- The agreed extensions to use for this session
- subProtocol- The agreed sub-protocol to use for this session
- pathParameters- The path parameters associated with the request that initiated this session or- nullif this is a client session
- secure- Was this session initiated over a secure connection?
- serverEndpointConfig- The configuration information for the server end point
- Throws:
- DeploymentException- if an invalid encode is specified
 
 - 
WsSession@Deprecated public WsSession(Endpoint localEndpoint, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.net.URI requestUri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap, java.lang.String queryString, java.security.Principal userPrincipal, java.lang.String httpSessionId, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, EndpointConfig endpointConfig) throws DeploymentException Deprecated.Unused. This will be removed in Tomcat 10.1Creates a new WebSocket session for communication between the two provided end points. The result ofThread.getContextClassLoader()at the time this constructor is called will be used when callingEndpoint.onClose(Session, CloseReason).- Parameters:
- localEndpoint- The end point managed by this code
- wsRemoteEndpoint- The other / remote endpoint
- wsWebSocketContainer- The container that created this session
- requestUri- The URI used to connect to this endpoint or- nullis this is a client session
- requestParameterMap- The parameters associated with the request that initiated this session or- nullif this is a client session
- queryString- The query string associated with the request that initiated this session or- nullif this is a client session
- userPrincipal- The principal associated with the request that initiated this session or- nullif this is a client session
- httpSessionId- The HTTP session ID associated with the request that initiated this session or- nullif this is a client session
- negotiatedExtensions- The agreed extensions to use for this session
- subProtocol- The agreed subprotocol to use for this session
- pathParameters- The path parameters associated with the request that initiated this session or- nullif this is a client session
- secure- Was this session initiated over a secure connection?
- endpointConfig- The configuration information for the endpoint
- Throws:
- DeploymentException- if an invalid encode is specified
 
 
- 
 - 
Method Detail- 
getInstanceManagerpublic InstanceManager getInstanceManager() 
 - 
getContainerpublic WebSocketContainer getContainer() Description copied from interface:javax.websocket.SessionGet the container that created this session.- Specified by:
- getContainerin interface- Session
- Returns:
- the container that created this session.
 
 - 
addMessageHandlerpublic void addMessageHandler(MessageHandler listener) Description copied from interface:javax.websocket.SessionRegisters aMessageHandlerfor incoming messages. Only oneMessageHandlermay be registered for each message type (text, binary, pong). The message type will be derived at runtime from the providedMessageHandlerinstance. It is not always possible to do this so it is better to useSession.addMessageHandler(Class, javax.websocket.MessageHandler.Partial)orSession.addMessageHandler(Class, javax.websocket.MessageHandler.Whole).- Specified by:
- addMessageHandlerin interface- Session
- Parameters:
- listener- The message handler for a incoming message
 
 - 
addMessageHandlerpublic <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler) throws java.lang.IllegalStateExceptionDescription copied from interface:javax.websocket.SessionRegisters aMessageHandlerfor partial incoming messages. Only oneMessageHandlermay be registered for each message type (text or binary, pong messages are never presented as partial messages).- Specified by:
- addMessageHandlerin interface- Session
- Type Parameters:
- T- The type of message that the given handler is intended for
- Parameters:
- clazz- The Class that implements T
- handler- The message handler for a incoming message
- Throws:
- java.lang.IllegalStateException- If a message handler has already been registered for the associated message type
 
 - 
addMessageHandlerpublic <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler) throws java.lang.IllegalStateExceptionDescription copied from interface:javax.websocket.SessionRegisters aMessageHandlerfor whole incoming messages. Only oneMessageHandlermay be registered for each message type (text, binary, pong).- Specified by:
- addMessageHandlerin interface- Session
- Type Parameters:
- T- The type of message that the given handler is intended for
- Parameters:
- clazz- The Class that implements T
- handler- The message handler for a incoming message
- Throws:
- java.lang.IllegalStateException- If a message handler has already been registered for the associated message type
 
 - 
getMessageHandlerspublic java.util.Set<MessageHandler> getMessageHandlers() - Specified by:
- getMessageHandlersin interface- Session
 
 - 
removeMessageHandlerpublic void removeMessageHandler(MessageHandler listener) - Specified by:
- removeMessageHandlerin interface- Session
 
 - 
getProtocolVersionpublic java.lang.String getProtocolVersion() - Specified by:
- getProtocolVersionin interface- Session
 
 - 
getNegotiatedSubprotocolpublic java.lang.String getNegotiatedSubprotocol() - Specified by:
- getNegotiatedSubprotocolin interface- Session
 
 - 
getNegotiatedExtensionspublic java.util.List<Extension> getNegotiatedExtensions() - Specified by:
- getNegotiatedExtensionsin interface- Session
 
 - 
isClosedpublic boolean isClosed() 
 - 
getMaxIdleTimeoutpublic long getMaxIdleTimeout() Description copied from interface:javax.websocket.SessionGet the idle timeout for this session.- Specified by:
- getMaxIdleTimeoutin interface- Session
- Returns:
- The current idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
 
 - 
setMaxIdleTimeoutpublic void setMaxIdleTimeout(long timeout) Description copied from interface:javax.websocket.SessionSet the idle timeout for this session.- Specified by:
- setMaxIdleTimeoutin interface- Session
- Parameters:
- timeout- The new idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
 
 - 
setMaxBinaryMessageBufferSizepublic void setMaxBinaryMessageBufferSize(int max) Description copied from interface:javax.websocket.SessionSet the current maximum buffer size for binary messages.- Specified by:
- setMaxBinaryMessageBufferSizein interface- Session
- Parameters:
- max- The new maximum buffer size in bytes
 
 - 
getMaxBinaryMessageBufferSizepublic int getMaxBinaryMessageBufferSize() Description copied from interface:javax.websocket.SessionGet the current maximum buffer size for binary messages.- Specified by:
- getMaxBinaryMessageBufferSizein interface- Session
- Returns:
- The current maximum buffer size in bytes
 
 - 
setMaxTextMessageBufferSizepublic void setMaxTextMessageBufferSize(int max) Description copied from interface:javax.websocket.SessionSet the maximum buffer size for text messages.- Specified by:
- setMaxTextMessageBufferSizein interface- Session
- Parameters:
- max- The new maximum buffer size in characters.
 
 - 
getMaxTextMessageBufferSizepublic int getMaxTextMessageBufferSize() Description copied from interface:javax.websocket.SessionGet the maximum buffer size for text messages.- Specified by:
- getMaxTextMessageBufferSizein interface- Session
- Returns:
- The maximum buffer size in characters.
 
 - 
getOpenSessionspublic java.util.Set<Session> getOpenSessions() Description copied from interface:javax.websocket.SessionObtain the set of open sessions associated with the same local endpoint as this session.- Specified by:
- getOpenSessionsin interface- Session
- Returns:
- The set of currently open sessions for the local endpoint that this session is associated with.
 
 - 
getAsyncRemotepublic RemoteEndpoint.Async getAsyncRemote() - Specified by:
- getAsyncRemotein interface- Session
 
 - 
getBasicRemotepublic RemoteEndpoint.Basic getBasicRemote() - Specified by:
- getBasicRemotein interface- Session
 
 - 
closepublic void close() throws java.io.IOExceptionDescription copied from interface:javax.websocket.SessionClose the connection to the remote end point using the codeCloseReason.CloseCodes.NORMAL_CLOSUREand an empty reason phrase.
 - 
closepublic void close(CloseReason closeReason) throws java.io.IOException Description copied from interface:javax.websocket.SessionClose the connection to the remote end point using the specified code and reason phrase.
 - 
doClosepublic void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal) WebSocket 1.0. Section 2.1.5. Need internal close method as spec requires that the local endpoint receives a 1006 on timeout.- Parameters:
- closeReasonMessage- The close reason to pass to the remote endpoint
- closeReasonLocal- The close reason to pass to the local endpoint
 
 - 
doClosepublic void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal, boolean closeSocket) WebSocket 1.0. Section 2.1.5. Need internal close method as spec requires that the local endpoint receives a 1006 on timeout.- Parameters:
- closeReasonMessage- The close reason to pass to the remote endpoint
- closeReasonLocal- The close reason to pass to the local endpoint
- closeSocket- Should the socket be closed immediately rather than waiting for the server to respond
 
 - 
onClosepublic void onClose(CloseReason closeReason) Called when a close message is received. Should only ever happen once. Also called after a protocol error when the ProtocolHandler needs to force the closing of the connection.- Parameters:
- closeReason- The reason contained within the received close message.
 
 - 
appendCloseReasonWithTruncationprotected static void appendCloseReasonWithTruncation(java.nio.ByteBuffer msg, java.lang.String reason)Use protected so unit tests can access this method directly.- Parameters:
- msg- The message
- reason- The reason
 
 - 
registerFutureprotected void registerFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh) Make the session aware of aFutureToSendHandlerthat will need to be forcibly closed if the session closes before theFutureToSendHandlercompletes.- Parameters:
- f2sh- The handler
 
 - 
unregisterFutureprotected void unregisterFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh) Remove aFutureToSendHandlerfrom the set of tracked instances.- Parameters:
- f2sh- The handler
 
 - 
getRequestURIpublic java.net.URI getRequestURI() - Specified by:
- getRequestURIin interface- Session
 
 - 
getRequestParameterMappublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameterMap() - Specified by:
- getRequestParameterMapin interface- Session
 
 - 
getQueryStringpublic java.lang.String getQueryString() - Specified by:
- getQueryStringin interface- Session
 
 - 
getUserPrincipalpublic java.security.Principal getUserPrincipal() - Specified by:
- getUserPrincipalin interface- Session
 
 - 
getPathParameterspublic java.util.Map<java.lang.String,java.lang.String> getPathParameters() - Specified by:
- getPathParametersin interface- Session
 
 - 
getIdpublic java.lang.String getId() Description copied from interface:javax.websocket.SessionProvides a unique identifier for the session. This identifier should not be relied upon to be generated from a secure random source.
 - 
getUserPropertiespublic java.util.Map<java.lang.String,java.lang.Object> getUserProperties() - Specified by:
- getUserPropertiesin interface- Session
 
 - 
getLocalpublic Endpoint getLocal() 
 - 
getHttpSessionIdpublic java.lang.String getHttpSessionId() 
 - 
getTextMessageHandlerprotected MessageHandler getTextMessageHandler() 
 - 
getBinaryMessageHandlerprotected MessageHandler getBinaryMessageHandler() 
 - 
getPongMessageHandlerprotected MessageHandler.Whole<PongMessage> getPongMessageHandler() 
 - 
updateLastActiveReadprotected void updateLastActiveRead() 
 - 
updateLastActiveWriteprotected void updateLastActiveWrite() 
 - 
checkExpirationprotected void checkExpiration() 
 - 
suspendpublic void suspend() Suspends the reading of the incoming messages.
 - 
resumepublic void resume() Resumes the reading of the incoming messages.
 
- 
 
-