Class WebSocketServerSockJsSession
java.lang.Object
org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,NativeWebSocketSession
,SockJsSession
,WebSocketSession
public class WebSocketServerSockJsSession
extends AbstractSockJsSession
implements NativeWebSocketSession
A SockJS session for use with the WebSocket transport.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Field Summary
Fields inherited from class org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
DISCONNECTED_CLIENT_LOG_CATEGORY, logger, responseLock
-
Constructor Summary
ConstructorDescriptionWebSocketServerSockJsSession
(String id, SockJsServiceConfig config, WebSocketHandler handler, Map<String, Object> attributes) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
disconnect
(CloseStatus status) Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.Return the negotiated sub-protocol.int
Get the configured maximum size for an incoming binary message.Determine the negotiated extensions.Return the headers used in the handshake request (nevernull
).Return the address on which the request was received.Return the underlying native WebSocketSession.<T> T
getNativeSession
(Class<T> requiredType) Return the underlying native WebSocketSession, if available.Return aPrincipal
instance containing the name of the authenticated user.Return the address of the remote client.int
Get the configured maximum size for an incoming text message.getUri()
Return the URI used to open the WebSocket connection.void
handleMessage
(TextMessage message, WebSocketSession wsSession) void
boolean
isActive()
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.void
sendMessageInternal
(String message) void
setBinaryMessageSizeLimit
(int messageSizeLimit) Configure the maximum size for an incoming binary message.void
setTextMessageSizeLimit
(int messageSizeLimit) Configure the maximum size for an incoming text message.protected void
writeFrameInternal
(SockJsFrame frame) Methods inherited from class org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
cancelHeartbeat, close, close, delegateConnectionClosed, delegateConnectionEstablished, delegateError, delegateMessages, disableHeartbeat, getAttributes, getId, getMessageCodec, getSockJsServiceConfig, getTimeSinceLastActive, isClosed, isNew, isOpen, scheduleHeartbeat, sendHeartbeat, sendMessage, toString, tryCloseWithSockJsTransportError, updateLastActiveTime, writeFrame
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.web.socket.WebSocketSession
close, close, getAttributes, getId, isOpen, sendMessage
-
Constructor Details
-
WebSocketServerSockJsSession
public WebSocketServerSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, @Nullable Map<String, Object> attributes)
-
-
Method Details
-
getUri
Description copied from interface:WebSocketSession
Return the URI used to open the WebSocket connection.- Specified by:
getUri
in interfaceWebSocketSession
-
getHandshakeHeaders
Description copied from interface:WebSocketSession
Return the headers used in the handshake request (nevernull
).- Specified by:
getHandshakeHeaders
in interfaceWebSocketSession
-
getPrincipal
Description copied from interface:WebSocketSession
Return aPrincipal
instance containing the name of the authenticated user.If the user has not been authenticated, the method returns
null
.- Specified by:
getPrincipal
in interfaceWebSocketSession
-
getLocalAddress
Description copied from interface:WebSocketSession
Return the address on which the request was received.- Specified by:
getLocalAddress
in interfaceWebSocketSession
-
getRemoteAddress
Description copied from interface:WebSocketSession
Return the address of the remote client.- Specified by:
getRemoteAddress
in interfaceWebSocketSession
-
getAcceptedProtocol
Description copied from interface:WebSocketSession
Return the negotiated sub-protocol.- Specified by:
getAcceptedProtocol
in interfaceWebSocketSession
- Returns:
- the protocol identifier, or
null
if no protocol was specified or negotiated successfully
-
setTextMessageSizeLimit
public void setTextMessageSizeLimit(int messageSizeLimit) Description copied from interface:WebSocketSession
Configure the maximum size for an incoming text message.- Specified by:
setTextMessageSizeLimit
in interfaceWebSocketSession
-
getTextMessageSizeLimit
public int getTextMessageSizeLimit()Description copied from interface:WebSocketSession
Get the configured maximum size for an incoming text message.- Specified by:
getTextMessageSizeLimit
in interfaceWebSocketSession
-
setBinaryMessageSizeLimit
public void setBinaryMessageSizeLimit(int messageSizeLimit) Description copied from interface:WebSocketSession
Configure the maximum size for an incoming binary message.- Specified by:
setBinaryMessageSizeLimit
in interfaceWebSocketSession
-
getBinaryMessageSizeLimit
public int getBinaryMessageSizeLimit()Description copied from interface:WebSocketSession
Get the configured maximum size for an incoming binary message.- Specified by:
getBinaryMessageSizeLimit
in interfaceWebSocketSession
-
getExtensions
Description copied from interface:WebSocketSession
Determine the negotiated extensions.- Specified by:
getExtensions
in interfaceWebSocketSession
- Returns:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
-
getNativeSession
Description copied from interface:NativeWebSocketSession
Return the underlying native WebSocketSession.- Specified by:
getNativeSession
in interfaceNativeWebSocketSession
-
getNativeSession
Description copied from interface:NativeWebSocketSession
Return the underlying native WebSocketSession, if available.- Specified by:
getNativeSession
in interfaceNativeWebSocketSession
- Parameters:
requiredType
- the required type of the session- Returns:
- the native session of the required type,
or
null
if not available
-
initializeDelegateSession
-
isActive
public boolean isActive()Description copied from class:AbstractSockJsSession
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through. During this "downtime" the session is still open but inactive and unable to send messages and therefore has to buffer them temporarily. A WebSocket session by contrast is stateful and remain active until closed.- Specified by:
isActive
in classAbstractSockJsSession
-
handleMessage
- Throws:
Exception
-
sendMessageInternal
- Specified by:
sendMessageInternal
in classAbstractSockJsSession
- Throws:
SockJsTransportFailureException
-
writeFrameInternal
- Specified by:
writeFrameInternal
in classAbstractSockJsSession
- Throws:
IOException
-
disconnect
Description copied from class:AbstractSockJsSession
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.- Specified by:
disconnect
in classAbstractSockJsSession
- Throws:
IOException
-