public abstract class AbstractClientSockJsSession extends Object implements WebSocketSession
WebSocketSession.
Provides processing of incoming SockJS message frames and delegates lifecycle
events and messages to the (application) WebSocketHandler.
Sub-classes implement actual send as well as disconnect logic.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractClientSockJsSession(TransportRequest request,
WebSocketHandler handler,
SettableListenableFuture<WebSocketSession> connectFuture) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterTransportClosed(CloseStatus closeStatus) |
void |
close()
Close the WebSocket connection with status 1000, i.e.
|
void |
close(CloseStatus status)
Close the WebSocket connection with the given close status.
|
protected void |
closeInternal(CloseStatus status) |
protected abstract void |
disconnect(CloseStatus status) |
Map<String,Object> |
getAttributes()
Return the map with attributes associated with the WebSocket session.
|
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request (never
null). |
String |
getId()
Return a unique session identifier.
|
SockJsMessageCodec |
getMessageCodec() |
Principal |
getPrincipal()
Return a
Principal instance containing the name
of the authenticated user. |
URI |
getUri()
Return the URI used to open the WebSocket connection.
|
WebSocketHandler |
getWebSocketHandler() |
void |
handleFrame(String payload) |
void |
handleTransportError(Throwable error) |
boolean |
isDisconnected() |
boolean |
isOpen()
Whether the underlying connection is open.
|
protected abstract void |
sendInternal(TextMessage textMessage) |
void |
sendMessage(WebSocketMessage<?> message)
Send a WebSocket message: either
TextMessage or BinaryMessage. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getLocalAddress, getRemoteAddress, getTextMessageSizeLimit, setBinaryMessageSizeLimit, setTextMessageSizeLimitprotected final Log logger
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler, SettableListenableFuture<WebSocketSession> connectFuture)
public String getId()
WebSocketSessiongetId in interface WebSocketSessionpublic 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 SockJsMessageCodec getMessageCodec()
public WebSocketHandler getWebSocketHandler()
public boolean isOpen()
WebSocketSessionisOpen in interface WebSocketSessionpublic boolean isDisconnected()
public final 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 WebSocketSessionIOExceptionConcurrentWebSocketSessionDecoratorprotected abstract void sendInternal(TextMessage textMessage) throws IOException
IOExceptionpublic final void close()
throws IOException
WebSocketSessionsession.close(CloseStatus.NORMAL);
close in interface Closeableclose in interface AutoCloseableclose in interface WebSocketSessionIOExceptionpublic final void close(CloseStatus status) throws IOException
WebSocketSessionclose in interface WebSocketSessionIOExceptionprotected void closeInternal(CloseStatus status) throws IOException
IOExceptionprotected abstract void disconnect(CloseStatus status) throws IOException
IOExceptionpublic void handleFrame(String payload)
public void handleTransportError(Throwable error)
public void afterTransportClosed(@Nullable CloseStatus closeStatus)