Top Description Inners Fields Constructors Methods
org.springframework.web.socket.sockjs.client

public abstract Class AbstractClientSockJsSession

extends Object
implements WebSocketSession
Class Inheritance
All Implemented Interfaces
org.springframework.web.socket.WebSocketSession, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.springframework.web.socket.sockjs.client.WebSocketClientSockJsSession, org.springframework.web.socket.sockjs.client.XhrClientSockJsSession
Imports
java.io.IOException, java.net.URI, java.security.Principal, java.util.Map, java.util.concurrent.CompletableFuture, .ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.socket.CloseStatus, .TextMessage, .WebSocketHandler, .WebSocketMessage, .WebSocketSession, org.springframework.web.socket.sockjs.frame.SockJsFrame, .SockJsMessageCodec

Base class for SockJS client implementations of WebSocketSession.

Provides processing of incoming SockJS message frames and delegates lifecycle events and messages to the (application) WebSocketHandler.

Subclasses implement actual send as well as disconnect logic.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private volatile CloseStatus
private final CompletableFuture<WebSocketSession>
protected final Log
private final TransportRequest
private volatile AbstractClientSockJsSession.State
private final WebSocketHandler

Constructor Summary

AccessConstructor and Description
protected
AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler, SettableListenableFuture<WebSocketSession> connectFuture)

Create a new AbstractClientSockJsSession.

protected

Method Summary

Modifier and TypeMethod and Description
public void
public final void
close()

Implements org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with status 1000, i.e. equivalent to:

session.close(CloseStatus.NORMAL);
public final void
close(CloseStatus status)

Implements org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with the given close status.

protected void
protected abstract void
public Map<String, Object>
getAttributes()

Implements org.springframework.web.socket.WebSocketSession.getAttributes.

Return the map with attributes associated with the WebSocket session.

public HttpHeaders
getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

public String
getId()

Implements org.springframework.web.socket.WebSocketSession.getId.

Return a unique session identifier.

public SockJsMessageCodec
public Principal
getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

pack-priv Runnable
getTimeoutTask()

Return a timeout cleanup task to invoke if the SockJS sessions is not fully established within the retransmission timeout period calculated in SockJsRequest based on the duration of the initial SockJS "Info" request.

public URI
getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

public WebSocketHandler
private void
public void
private void
private void
public void
public boolean
public boolean
isOpen()

Implements org.springframework.web.socket.WebSocketSession.isOpen.

Whether the underlying connection is open.

private boolean
protected abstract void
public final void
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, Object> attributes
closeStatusback to summary
private volatile CloseStatus closeStatus
Annotations
@Nullable
connectFutureback to summary
private final CompletableFuture<WebSocketSession> connectFuture
loggerback to summary
protected final Log logger
requestback to summary
private final TransportRequest request
stateback to summary
private volatile AbstractClientSockJsSession.State state
Annotations
@Nullable
webSocketHandlerback to summary
private final WebSocketHandler webSocketHandler

Constructor Detail

AbstractClientSockJsSessionback to summary
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler, SettableListenableFuture<WebSocketSession> connectFuture)

Create a new AbstractClientSockJsSession.

Annotations
@Deprecated
since:6.0
AbstractClientSockJsSessionback to summary
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler, CompletableFuture<WebSocketSession> connectFuture)

Method Detail

afterTransportClosedback to summary
public void afterTransportClosed(CloseStatus closeStatus)
closeback to summary
public final void close() throws IOException

Implements org.springframework.web.socket.WebSocketSession.close.

Doc from org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with status 1000, i.e. equivalent to:

session.close(CloseStatus.NORMAL);
Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

closeback to summary
public final void close(CloseStatus status) throws IOException

Implements org.springframework.web.socket.WebSocketSession.close.

Doc from org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with the given close status.

Annotations
@Override
closeInternalback to summary
protected void closeInternal(CloseStatus status) throws IOException
disconnectback to summary
protected abstract void disconnect(CloseStatus status) throws IOException
getAttributesback to summary
public Map<String, Object> getAttributes()

Implements org.springframework.web.socket.WebSocketSession.getAttributes.

Doc from org.springframework.web.socket.WebSocketSession.getAttributes.

Return 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 via WebSocketClient handshake methods.

Returns:Map<String, Object>

a Map with the session attributes (never null)

Annotations
@Override
getHandshakeHeadersback to summary
public HttpHeaders getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Doc from org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

Annotations
@Override
getIdback to summary
public String getId()

Implements org.springframework.web.socket.WebSocketSession.getId.

Doc from org.springframework.web.socket.WebSocketSession.getId.

Return a unique session identifier.

Annotations
@Override
getMessageCodecback to summary
public SockJsMessageCodec getMessageCodec()
getPrincipalback to summary
public Principal getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Doc from org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

If the user has not been authenticated, the method returns null.

Annotations
@Override
getTimeoutTaskback to summary
pack-priv Runnable getTimeoutTask()

Return a timeout cleanup task to invoke if the SockJS sessions is not fully established within the retransmission timeout period calculated in SockJsRequest based on the duration of the initial SockJS "Info" request.

getUriback to summary
public URI getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Doc from org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

Annotations
@Override
getWebSocketHandlerback to summary
public WebSocketHandler getWebSocketHandler()
handleCloseFrameback to summary
private void handleCloseFrame(SockJsFrame frame)
handleFrameback to summary
public void handleFrame(String payload)
handleMessageFrameback to summary
private void handleMessageFrame(SockJsFrame frame)
handleOpenFrameback to summary
private void handleOpenFrame()
handleTransportErrorback to summary
public void handleTransportError(Throwable error)
isDisconnectedback to summary
public boolean isDisconnected()
isOpenback to summary
public boolean isOpen()

Implements org.springframework.web.socket.WebSocketSession.isOpen.

Doc from org.springframework.web.socket.WebSocketSession.isOpen.

Whether the underlying connection is open.

Annotations
@Override
isUserSetStatusback to summary
private boolean isUserSetStatus(CloseStatus status)
sendInternalback to summary
protected abstract void sendInternal(TextMessage textMessage) throws IOException
sendMessageback to summary
public final void sendMessage(WebSocketMessage<?> message) throws IOException

Implements org.springframework.web.socket.WebSocketSession.sendMessage.

Doc from org.springframework.web.socket.WebSocketSession.sendMessage.

Send a WebSocket message: either 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.

Annotations
@Override
silentCloseback to summary
private void silentClose(CloseStatus status)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.socket.sockjs.client back to summary

private final Enum AbstractClientSockJsSession.State

extends Enum<AbstractClientSockJsSession.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final AbstractClientSockJsSession.State
public static final AbstractClientSockJsSession.State
public static final AbstractClientSockJsSession.State
public static final AbstractClientSockJsSession.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AbstractClientSockJsSession.State
public static AbstractClientSockJsSession.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLOSEDback to summary
public static final AbstractClientSockJsSession.State CLOSED
CLOSINGback to summary
public static final AbstractClientSockJsSession.State CLOSING
NEWback to summary
public static final AbstractClientSockJsSession.State NEW
OPENback to summary
public static final AbstractClientSockJsSession.State OPEN

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static AbstractClientSockJsSession.State valueOf(String name)
valuesback to summary
public static AbstractClientSockJsSession.State[] values()