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()
WebSocketSession
getId
in interface WebSocketSession
@Nullable public URI getUri()
WebSocketSession
getUri
in interface WebSocketSession
public HttpHeaders getHandshakeHeaders()
WebSocketSession
null
).getHandshakeHeaders
in interface WebSocketSession
public Map<String,Object> getAttributes()
WebSocketSession
On 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 WebSocketSession
null
)public Principal getPrincipal()
WebSocketSession
Principal
instance containing the name
of the authenticated user.
If the user has not been authenticated, the method returns null
.
getPrincipal
in interface WebSocketSession
public InetSocketAddress getLocalAddress()
WebSocketSession
getLocalAddress
in interface WebSocketSession
public InetSocketAddress getRemoteAddress()
WebSocketSession
getRemoteAddress
in interface WebSocketSession
public String getAcceptedProtocol()
WebSocketSession
getAcceptedProtocol
in interface WebSocketSession
null
if no protocol
was specified or negotiated successfullypublic List<WebSocketExtension> getExtensions()
WebSocketSession
getExtensions
in interface WebSocketSession
public void setTextMessageSizeLimit(int messageSizeLimit)
WebSocketSession
setTextMessageSizeLimit
in interface WebSocketSession
public int getTextMessageSizeLimit()
WebSocketSession
getTextMessageSizeLimit
in interface WebSocketSession
public void setBinaryMessageSizeLimit(int messageSizeLimit)
WebSocketSession
setBinaryMessageSizeLimit
in interface WebSocketSession
public int getBinaryMessageSizeLimit()
WebSocketSession
getBinaryMessageSizeLimit
in interface WebSocketSession
public boolean isOpen()
WebSocketSession
isOpen
in interface WebSocketSession
public void sendMessage(WebSocketMessage<?> message) throws IOException
WebSocketSession
TextMessage
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 WebSocketSession
IOException
ConcurrentWebSocketSessionDecorator
public void close() throws IOException
WebSocketSession
session.close(CloseStatus.NORMAL);
close
in interface Closeable
close
in interface AutoCloseable
close
in interface WebSocketSession
IOException
public void close(CloseStatus status) throws IOException
WebSocketSession
close
in interface WebSocketSession
IOException