org.springframework.web.socket.sockjs.client

## Class AbstractClientSockJsSession

- java.lang.Object
- - org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession

All Implemented Interfaces:
  Closeable, AutoCloseable, WebSocketSession

Direct Known Subclasses:
  WebSocketClientSockJsSession, XhrClientSockJsSession

    public abstract class AbstractClientSockJsSession
    extends Object
    implements WebSocketSession

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`. Sub-classes implement actual send as well as disconnect logic.

Since:
  4.1
Author:
  Rossen Stoyanchev, Juergen Hoeller

### Field Summary

Fields
`protected Log` `logger`

### Constructor Summary

Constructors
`protected` `AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler, org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`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.
`org.springframework.http.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()` Return whether the connection is still open.
`protected abstract void` `sendInternal(TextMessage textMessage)`
`void` `sendMessage(WebSocketMessage<?> message)` Send a WebSocket message: either `TextMessage` or `BinaryMessage`.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.web.socket.WebSocketSession

`getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getLocalAddress, getRemoteAddress, getTextMessageSizeLimit, setBinaryMessageSizeLimit, setTextMessageSizeLimit`

### Field Detail

#### logger

    protected final Log logger

### Constructor Detail

#### AbstractClientSockJsSession

    protected AbstractClientSockJsSession(TransportRequest request,
                                          WebSocketHandler handler,
                                          org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture)

### Method Detail

#### getId

    public String getId()

Description copied from interface: `WebSocketSession`
Return a unique session identifier.

Specified by:
  `getId` in interface `WebSocketSession`

#### getUri

    public URI getUri()

Description copied from interface: `WebSocketSession`
Return the URI used to open the WebSocket connection.

Specified by:
  `getUri` in interface `WebSocketSession`

#### getHandshakeHeaders

    public org.springframework.http.HttpHeaders getHandshakeHeaders()

Description copied from interface: `WebSocketSession`
Return the headers used in the handshake request (never `null`).

Specified by:
  `getHandshakeHeaders` in interface `WebSocketSession`

#### getAttributes

    public Map<String,Object> getAttributes()

Description copied from interface: `WebSocketSession`
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.

Specified by:
  `getAttributes` in interface `WebSocketSession`
Returns:
  a Map with the session attributes (never `null`)

#### getPrincipal

    public Principal getPrincipal()

Description copied from interface: `WebSocketSession`
Return a `Principal` instance containing the name of the authenticated user.

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

Specified by:
  `getPrincipal` in interface `WebSocketSession`

#### getMessageCodec

    public SockJsMessageCodec getMessageCodec()

#### getWebSocketHandler

    public WebSocketHandler getWebSocketHandler()

#### isOpen

    public boolean isOpen()

Description copied from interface: `WebSocketSession`
Return whether the connection is still open.

Specified by:
  `isOpen` in interface `WebSocketSession`

#### isDisconnected

    public boolean isDisconnected()

#### sendMessage

    public final void sendMessage(WebSocketMessage<?> message)
                           throws IOException

Description copied from interface: `WebSocketSession`
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`.

Specified by:
  `sendMessage` in interface `WebSocketSession`
Throws:
  `IOException`
See Also:
  `ConcurrentWebSocketSessionDecorator`

#### sendInternal

    protected abstract void sendInternal(TextMessage textMessage)
                                  throws IOException

Throws:
  `IOException`

#### close

    public final void close()
                     throws IOException

Description copied from interface: `WebSocketSession`
Close the WebSocket connection with status 1000, i.e. equivalent to:

     session.close(CloseStatus.NORMAL);

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `WebSocketSession`
Throws:
  `IOException`

#### close

    public final void close(CloseStatus status)
                     throws IOException

Description copied from interface: `WebSocketSession`
Close the WebSocket connection with the given close status.

Specified by:
  `close` in interface `WebSocketSession`
Throws:
  `IOException`

#### closeInternal

    protected void closeInternal(CloseStatus status)
                          throws IOException

Throws:
  `IOException`

#### disconnect

    protected abstract void disconnect(CloseStatus status)
                                throws IOException

Throws:
  `IOException`

#### handleFrame

    public void handleFrame(String payload)

#### handleTransportError

    public void handleTransportError(Throwable error)

#### afterTransportClosed

    public void afterTransportClosed(@Nullable
                                     CloseStatus closeStatus)

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`