public interface WebSocketSession
extends java.io.Closeable
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.
|
java.lang.String |
getAcceptedProtocol()
Return the negotiated sub-protocol.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Return the map with attributes associated with the WebSocket session.
|
int |
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.
|
java.util.List<WebSocketExtension> |
getExtensions()
Determine the negotiated extensions.
|
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request (never
null ). |
java.lang.String |
getId()
Return a unique session identifier.
|
java.net.InetSocketAddress |
getLocalAddress()
Return the address on which the request was received.
|
java.security.Principal |
getPrincipal()
Return a
Principal instance containing the name
of the authenticated user. |
java.net.InetSocketAddress |
getRemoteAddress()
Return the address of the remote client.
|
int |
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.
|
java.net.URI |
getUri()
Return the URI used to open the WebSocket connection.
|
boolean |
isOpen()
Return whether the connection is still 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.
|
java.lang.String getId()
@Nullable java.net.URI getUri()
HttpHeaders getHandshakeHeaders()
null
).java.util.Map<java.lang.String,java.lang.Object> getAttributes()
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.
null
)@Nullable java.security.Principal getPrincipal()
Principal
instance containing the name
of the authenticated user.
If the user has not been authenticated, the method returns null
.
@Nullable java.net.InetSocketAddress getLocalAddress()
@Nullable java.net.InetSocketAddress getRemoteAddress()
@Nullable java.lang.String getAcceptedProtocol()
null
if no protocol
was specified or negotiated successfullyvoid setTextMessageSizeLimit(int messageSizeLimit)
int getTextMessageSizeLimit()
void setBinaryMessageSizeLimit(int messageSizeLimit)
int getBinaryMessageSizeLimit()
java.util.List<WebSocketExtension> getExtensions()
void sendMessage(WebSocketMessage<?> message) throws java.io.IOException
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
.
java.io.IOException
ConcurrentWebSocketSessionDecorator
boolean isOpen()
void close() throws java.io.IOException
session.close(CloseStatus.NORMAL);
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
void close(CloseStatus status) throws java.io.IOException
java.io.IOException