Class WebSocketSessionDecorator
java.lang.Object
org.springframework.web.socket.handler.WebSocketSessionDecorator
- All Implemented Interfaces:
Closeable,AutoCloseable,WebSocketSession
- Direct Known Subclasses:
ConcurrentWebSocketSessionDecorator
Wraps another
WebSocketSession instance
and delegates to it.
Also provides a getDelegate() method to return the decorated session
as well as a getLastSession() method to go through all nested delegates
and return the "last" session.
- Since:
- 4.0.3
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the WebSocket connection with status 1000, i.e.voidclose(CloseStatus status) Close the WebSocket connection with the given close status.Return the negotiated sub-protocol.Return the map with attributes associated with the WebSocket session.intGet the configured maximum size for an incoming binary message.Determine the negotiated extensions.Return the headers used in the handshake request (nevernull).getId()Return a unique session identifier.Return the address on which the request was received.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.booleanisOpen()Whether the underlying connection is open.voidsendMessage(WebSocketMessage<?> message) Send a WebSocket message: eitherTextMessageorBinaryMessage.voidsetBinaryMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming binary message.voidsetTextMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming text message.toString()static WebSocketSessionunwrap(WebSocketSession session)
-
Constructor Details
-
WebSocketSessionDecorator
-
-
Method Details
-
getDelegate
-
getLastSession
-
unwrap
-
getId
Description copied from interface:WebSocketSessionReturn a unique session identifier.- Specified by:
getIdin interfaceWebSocketSession
-
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
-
getAttributes
Description copied from interface:WebSocketSessionReturn the map with attributes associated with the WebSocket session.On the server side the map can be populated initially through a
HandshakeInterceptor. On the client side the map can be populated viaWebSocketClienthandshake methods.- Specified by:
getAttributesin interfaceWebSocketSession- Returns:
- a Map with the session attributes (never
null)
-
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
-
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
-
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
-
isOpen
public boolean isOpen()Description copied from interface:WebSocketSessionWhether the underlying connection is open.- Specified by:
isOpenin interfaceWebSocketSession
-
sendMessage
Description copied from interface:WebSocketSessionSend a WebSocket message: eitherTextMessageorBinaryMessage.Note: The underlying standard WebSocket session (JSR-356) does not allow concurrent sending. Therefore sending must be synchronized. To ensure that, one option is to wrap the
WebSocketSessionwith theConcurrentWebSocketSessionDecorator.- Specified by:
sendMessagein interfaceWebSocketSession- Throws:
IOException- See Also:
-
close
Description copied from interface:WebSocketSessionClose the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL);
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceWebSocketSession- Throws:
IOException
-
close
Description copied from interface:WebSocketSessionClose the WebSocket connection with the given close status.- Specified by:
closein interfaceWebSocketSession- Throws:
IOException
-
toString
-