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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the WebSocket connection with status 1000, i.e.void
close
(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.int
Get 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 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.boolean
isOpen()
Whether the underlying connection is open.void
sendMessage
(WebSocketMessage<?> message) Send a WebSocket message: eitherTextMessage
orBinaryMessage
.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.toString()
static WebSocketSession
unwrap
(WebSocketSession session)
-
Constructor Details
-
WebSocketSessionDecorator
-
-
Method Details
-
getDelegate
-
getLastSession
-
unwrap
-
getId
Description copied from interface:WebSocketSession
Return a unique session identifier.- Specified by:
getId
in interfaceWebSocketSession
-
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
-
getAttributes
Description copied from interface:WebSocketSession
Return 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 viaWebSocketClient
handshake methods.- Specified by:
getAttributes
in interfaceWebSocketSession
- Returns:
- a Map with the session attributes (never
null
)
-
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
-
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
-
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
-
isOpen
public boolean isOpen()Description copied from interface:WebSocketSession
Whether the underlying connection is open.- Specified by:
isOpen
in interfaceWebSocketSession
-
sendMessage
Description copied from interface:WebSocketSession
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.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
WebSocketSession
with theConcurrentWebSocketSessionDecorator
.- Specified by:
sendMessage
in interfaceWebSocketSession
- Throws:
IOException
- See Also:
-
close
Description copied from interface:WebSocketSession
Close the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL);
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceWebSocketSession
- Throws:
IOException
-
close
Description copied from interface:WebSocketSession
Close the WebSocket connection with the given close status.- Specified by:
close
in interfaceWebSocketSession
- Throws:
IOException
-
toString
-