Interface WebSocketSession
- All Superinterfaces:
- AutoCloseable, Closeable
- All Known Subinterfaces:
- NativeWebSocketSession, SockJsSession
- All Known Implementing Classes:
- AbstractClientSockJsSession, AbstractHttpSockJsSession, AbstractSockJsSession, AbstractWebSocketSession, ConcurrentWebSocketSessionDecorator, JettyWebSocketSession, PollingSockJsSession, StandardWebSocketSession, StreamingSockJsSession, WebSocketClientSockJsSession, WebSocketServerSockJsSession, WebSocketSessionDecorator, XhrClientSockJsSession
A WebSocket session abstraction. Allows sending messages over a WebSocket
connection and closing it.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
- 
Method SummaryModifier 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.
- 
Method Details- 
getIdString getId()Return a unique session identifier.
- 
getUri
- 
getHandshakeHeadersHttpHeaders getHandshakeHeaders()Return the headers used in the handshake request (nevernull).
- 
getAttributesReturn 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.- Returns:
- a Map with the session attributes (never null)
 
- 
getPrincipal
- 
getLocalAddress@Nullable InetSocketAddress getLocalAddress()Return the address on which the request was received.Note: The localAddress is not always possible to access, which is the case with the Standard WebSocket client API, and accordingly StandardWebSocketClientreturnsnull.
- 
getRemoteAddress@Nullable InetSocketAddress getRemoteAddress()Return the address of the remote client.
- 
getAcceptedProtocol
- 
setTextMessageSizeLimitvoid setTextMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming text message.
- 
getTextMessageSizeLimitint getTextMessageSizeLimit()Get the configured maximum size for an incoming text message.
- 
setBinaryMessageSizeLimitvoid setBinaryMessageSizeLimit(int messageSizeLimit) Configure the maximum size for an incoming binary message.
- 
getBinaryMessageSizeLimitint getBinaryMessageSizeLimit()Get the configured maximum size for an incoming binary message.
- 
getExtensionsList<WebSocketExtension> getExtensions()Determine the negotiated extensions.- Returns:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
 
- 
sendMessageSend 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.- Throws:
- IOException
- See Also:
 
- 
isOpenboolean isOpen()Whether the underlying connection is open.
- 
closeClose the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL); - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException
 
- 
closeClose the WebSocket connection with the given close status.- Throws:
- IOException
 
 
-