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, disconnectedClientLogger, logger, responseLock -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketServerSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, Map<String, Object> attributes) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddisconnect(CloseStatus status) Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.Return the negotiated sub-protocol.intGet 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> TgetNativeSession(Class<T> requiredType) Return the underlying native WebSocketSession, if available.Return aPrincipalinstance containing the name of the authenticated user.Return the address of the remote client.intGet the configured maximum size for an incoming text message.getUri()Return the URI used to open the WebSocket connection.voidhandleMessage(TextMessage message, WebSocketSession wsSession) voidbooleanisActive()Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.voidsendMessageInternal(String message) voidsetBinaryMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming binary message.voidsetTextMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming text message.protected voidwriteFrameInternal(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, writeFrameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:WebSocketSessionReturn the URI used to open the WebSocket connection.- Specified by:
getUriin interfaceWebSocketSession
-
getHandshakeHeaders
Description copied from interface:WebSocketSessionReturn the headers used in the handshake request (nevernull).- Specified by:
getHandshakeHeadersin interfaceWebSocketSession
-
getPrincipal
Description copied from interface:WebSocketSessionReturn aPrincipalinstance containing the name of the authenticated user.If the user has not been authenticated, the method returns
null.- Specified by:
getPrincipalin interfaceWebSocketSession
-
getLocalAddress
Description copied from interface:WebSocketSessionReturn the address on which the request was received.- Specified by:
getLocalAddressin interfaceWebSocketSession
-
getRemoteAddress
Description copied from interface:WebSocketSessionReturn the address of the remote client.- Specified by:
getRemoteAddressin interfaceWebSocketSession
-
getAcceptedProtocol
Description copied from interface:WebSocketSessionReturn the negotiated sub-protocol.- Specified by:
getAcceptedProtocolin interfaceWebSocketSession- Returns:
- the protocol identifier, or
nullif no protocol was specified or negotiated successfully
-
setTextMessageSizeLimit
public void setTextMessageSizeLimit(int messageSizeLimit) Description copied from interface:WebSocketSessionConfigure the maximum size for an incoming text message.- Specified by:
setTextMessageSizeLimitin interfaceWebSocketSession
-
getTextMessageSizeLimit
public int getTextMessageSizeLimit()Description copied from interface:WebSocketSessionGet the configured maximum size for an incoming text message.- Specified by:
getTextMessageSizeLimitin interfaceWebSocketSession
-
setBinaryMessageSizeLimit
public void setBinaryMessageSizeLimit(int messageSizeLimit) Description copied from interface:WebSocketSessionConfigure the maximum size for an incoming binary message.- Specified by:
setBinaryMessageSizeLimitin interfaceWebSocketSession
-
getBinaryMessageSizeLimit
public int getBinaryMessageSizeLimit()Description copied from interface:WebSocketSessionGet the configured maximum size for an incoming binary message.- Specified by:
getBinaryMessageSizeLimitin interfaceWebSocketSession
-
getExtensions
Description copied from interface:WebSocketSessionDetermine the negotiated extensions.- Specified by:
getExtensionsin interfaceWebSocketSession- Returns:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
-
getNativeSession
Description copied from interface:NativeWebSocketSessionReturn the underlying native WebSocketSession.- Specified by:
getNativeSessionin interfaceNativeWebSocketSession
-
getNativeSession
Description copied from interface:NativeWebSocketSessionReturn the underlying native WebSocketSession, if available.- Specified by:
getNativeSessionin interfaceNativeWebSocketSession- Parameters:
requiredType- the required type of the session- Returns:
- the native session of the required type,
or
nullif not available
-
initializeDelegateSession
-
isActive
public boolean isActive()Description copied from class:AbstractSockJsSessionPolling 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:
isActivein classAbstractSockJsSession
-
handleMessage
- Throws:
Exception
-
sendMessageInternal
- Specified by:
sendMessageInternalin classAbstractSockJsSession- Throws:
SockJsTransportFailureException
-
writeFrameInternal
- Specified by:
writeFrameInternalin classAbstractSockJsSession- Throws:
IOException
-
disconnect
Description copied from class:AbstractSockJsSessionActually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.- Specified by:
disconnectin classAbstractSockJsSession- Throws:
IOException
-