public class WebSocketSessionDecorator extends Object implements WebSocketSession
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.
| Constructor and Description |
|---|
WebSocketSessionDecorator(WebSocketSession session) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the WebSocket connection with status 1000, i.e.
|
void |
close(CloseStatus status)
Close the WebSocket connection with the given close status.
|
String |
getAcceptedProtocol()
Return the negotiated sub-protocol.
|
Map<String,Object> |
getAttributes()
Return the map with attributes associated with the WebSocket session.
|
int |
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.
|
WebSocketSession |
getDelegate() |
List<WebSocketExtension> |
getExtensions()
Determine the negotiated extensions.
|
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request (never
null). |
String |
getId()
Return a unique session identifier.
|
WebSocketSession |
getLastSession() |
InetSocketAddress |
getLocalAddress()
Return the address on which the request was received.
|
Principal |
getPrincipal()
Return a
Principal instance containing the name
of the authenticated user. |
InetSocketAddress |
getRemoteAddress()
Return the address of the remote client.
|
int |
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.
|
URI |
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: either
TextMessage or BinaryMessage. |
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.
|
String |
toString() |
static WebSocketSession |
unwrap(WebSocketSession session) |
public WebSocketSessionDecorator(WebSocketSession session)
public WebSocketSession getDelegate()
public WebSocketSession getLastSession()
public static WebSocketSession unwrap(WebSocketSession session)
public String getId()
WebSocketSessiongetId in interface WebSocketSession@Nullable public URI getUri()
WebSocketSessiongetUri in interface WebSocketSessionpublic HttpHeaders getHandshakeHeaders()
WebSocketSessionnull).getHandshakeHeaders in interface WebSocketSessionpublic Map<String,Object> getAttributes()
WebSocketSessionOn the server side the map can be populated initially through a
HandshakeInterceptor. On the client side the map can be populated via
WebSocketClient handshake methods.
getAttributes in interface WebSocketSessionnull)public Principal getPrincipal()
WebSocketSessionPrincipal instance containing the name
of the authenticated user.
If the user has not been authenticated, the method returns null.
getPrincipal in interface WebSocketSessionpublic InetSocketAddress getLocalAddress()
WebSocketSessiongetLocalAddress in interface WebSocketSessionpublic InetSocketAddress getRemoteAddress()
WebSocketSessiongetRemoteAddress in interface WebSocketSessionpublic String getAcceptedProtocol()
WebSocketSessiongetAcceptedProtocol in interface WebSocketSessionnull if no protocol
was specified or negotiated successfullypublic List<WebSocketExtension> getExtensions()
WebSocketSessiongetExtensions in interface WebSocketSessionpublic void setTextMessageSizeLimit(int messageSizeLimit)
WebSocketSessionsetTextMessageSizeLimit in interface WebSocketSessionpublic int getTextMessageSizeLimit()
WebSocketSessiongetTextMessageSizeLimit in interface WebSocketSessionpublic void setBinaryMessageSizeLimit(int messageSizeLimit)
WebSocketSessionsetBinaryMessageSizeLimit in interface WebSocketSessionpublic int getBinaryMessageSizeLimit()
WebSocketSessiongetBinaryMessageSizeLimit in interface WebSocketSessionpublic boolean isOpen()
WebSocketSessionisOpen in interface WebSocketSessionpublic void sendMessage(WebSocketMessage<?> message) throws IOException
WebSocketSessionTextMessage or BinaryMessage.
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 the
ConcurrentWebSocketSessionDecorator.
sendMessage in interface WebSocketSessionIOExceptionConcurrentWebSocketSessionDecoratorpublic void close()
throws IOException
WebSocketSessionsession.close(CloseStatus.NORMAL);
close in interface Closeableclose in interface AutoCloseableclose in interface WebSocketSessionIOExceptionpublic void close(CloseStatus status) throws IOException
WebSocketSessionclose in interface WebSocketSessionIOException