org.springframework.web.socket.sockjs.transport.session

## Class WebSocketServerSockJsSession

- java.lang.Object
- - org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
  - - org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession

All Implemented Interfaces:
  Closeable, AutoCloseable, NativeWebSocketSession, SockJsSession, WebSocketSession

    public class WebSocketServerSockJsSession
    extends AbstractSockJsSession
    implements NativeWebSocketSession

A SockJS session for use with the WebSocket transport.

Since:
  4.0
Author:
  Rossen Stoyanchev, Juergen Hoeller

### Field Summary

### Fields inherited from class org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession

`DISCONNECTED_CLIENT_LOG_CATEGORY, disconnectedClientLogger, logger, responseLock`

### Constructor Summary

Constructors
Constructor and Description
`WebSocketServerSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, Map<String,Object> attributes)`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `disconnect(CloseStatus status)` Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.
`String` `getAcceptedProtocol()` Return the negotiated sub-protocol.
`int` `getBinaryMessageSizeLimit()` Get the configured maximum size for an incoming binary message.
`List<WebSocketExtension>` `getExtensions()` Determine the negotiated extensions.
`org.springframework.http.HttpHeaders` `getHandshakeHeaders()` Return the headers used in the handshake request (never `null`).
`InetSocketAddress` `getLocalAddress()` Return the address on which the request was received.
`Object` `getNativeSession()` Return the underlying native WebSocketSession.
`<T> T` `getNativeSession(Class<T> requiredType)` Return the underlying native WebSocketSession, if available.
`Principal` `getPrincipal()` Return a `Principal` instance containing the name of the authenticated user.
`InetSocketAddress` `getRemoteAddress()` Return the address of the remote client.
`int` `getTextMessageSizeLimit()` Get the configured maximum size for an incoming text message.
`URI` `getUri()` Return the URI used to open the WebSocket connection.
`void` `handleMessage(TextMessage message, WebSocketSession wsSession)`
`void` `initializeDelegateSession(WebSocketSession session)`
`boolean` `isActive()` Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.
`void` `sendMessageInternal(String message)`
`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.
`protected void` `writeFrameInternal(SockJsFrame frame)`

### Methods inherited from class org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession

`cancelHeartbeat, close, close, delegateConnectionClosed, delegateConnectionEstablished, delegateError, delegateMessages, disableHeartbeat, getAttributes, getId, getMessageCodec, getSockJsServiceConfig, getTimeSinceLastActive, isClosed, isNew, isOpen, scheduleHeartbeat, sendHeartbeat, sendMessage, toString, tryCloseWithSockJsTransportError, updateLastActiveTime, writeFrame`

### 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

`close, close, getAttributes, getId, isOpen, sendMessage`

### Constructor Detail

#### WebSocketServerSockJsSession

    public WebSocketServerSockJsSession(String id,
                                        SockJsServiceConfig config,
                                        WebSocketHandler handler,
                                        @Nullable
                                        Map<String,Object> attributes)

### Method Detail

#### getUri

    @Nullable
    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`

#### 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`

#### getLocalAddress

    public InetSocketAddress getLocalAddress()

Description copied from interface: `WebSocketSession`
Return the address on which the request was received.

Specified by:
  `getLocalAddress` in interface `WebSocketSession`

#### getRemoteAddress

    public InetSocketAddress getRemoteAddress()

Description copied from interface: `WebSocketSession`
Return the address of the remote client.

Specified by:
  `getRemoteAddress` in interface `WebSocketSession`

#### getAcceptedProtocol

    public String getAcceptedProtocol()

Description copied from interface: `WebSocketSession`
Return the negotiated sub-protocol.

Specified by:
  `getAcceptedProtocol` in interface `WebSocketSession`
Returns:
  the protocol identifier, or `null` if no protocol was specified or negotiated successfully

#### setTextMessageSizeLimit

    public void setTextMessageSizeLimit(int messageSizeLimit)

Description copied from interface: `WebSocketSession`
Configure the maximum size for an incoming text message.

Specified by:
  `setTextMessageSizeLimit` in interface `WebSocketSession`

#### getTextMessageSizeLimit

    public int getTextMessageSizeLimit()

Description copied from interface: `WebSocketSession`
Get the configured maximum size for an incoming text message.

Specified by:
  `getTextMessageSizeLimit` in interface `WebSocketSession`

#### setBinaryMessageSizeLimit

    public void setBinaryMessageSizeLimit(int messageSizeLimit)

Description copied from interface: `WebSocketSession`
Configure the maximum size for an incoming binary message.

Specified by:
  `setBinaryMessageSizeLimit` in interface `WebSocketSession`

#### getBinaryMessageSizeLimit

    public int getBinaryMessageSizeLimit()

Description copied from interface: `WebSocketSession`
Get the configured maximum size for an incoming binary message.

Specified by:
  `getBinaryMessageSizeLimit` in interface `WebSocketSession`

#### getExtensions

    public List<WebSocketExtension> getExtensions()

Description copied from interface: `WebSocketSession`
Determine the negotiated extensions.

Specified by:
  `getExtensions` in interface `WebSocketSession`
Returns:
  the list of extensions, or an empty list if no extension was specified or negotiated successfully

#### getNativeSession

    public Object getNativeSession()

Description copied from interface: `NativeWebSocketSession`
Return the underlying native WebSocketSession.

Specified by:
  `getNativeSession` in interface `NativeWebSocketSession`

#### getNativeSession

    @Nullable
    public <T> T getNativeSession(@Nullable
                                            Class<T> requiredType)

Description copied from interface: `NativeWebSocketSession`
Return the underlying native WebSocketSession, if available.

Specified by:
  `getNativeSession` in interface `NativeWebSocketSession`
Parameters:
  `requiredType` - the required type of the session
Returns:
  the native session of the required type, or `null` if not available

#### initializeDelegateSession

    public void initializeDelegateSession(WebSocketSession session)

#### isActive

    public boolean isActive()

Description copied from class: `AbstractSockJsSession`
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through. During this "downtime" the session is still open but inactive and unable to send messages and therefore has to buffer them temporarily. A WebSocket session by contrast is stateful and remain active until closed.

Specified by:
  `isActive` in class `AbstractSockJsSession`

#### handleMessage

    public void handleMessage(TextMessage message,
                              WebSocketSession wsSession)
                       throws Exception

Throws:
  `Exception`

#### sendMessageInternal

    public void sendMessageInternal(String message)
                             throws SockJsTransportFailureException

Specified by:
  `sendMessageInternal` in class `AbstractSockJsSession`
Throws:
  `SockJsTransportFailureException`

#### writeFrameInternal

    protected void writeFrameInternal(SockJsFrame frame)
                               throws IOException

Specified by:
  `writeFrameInternal` in class `AbstractSockJsSession`
Throws:
  `IOException`

#### disconnect

    protected void disconnect(CloseStatus status)
                       throws IOException

Description copied from class: `AbstractSockJsSession`
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.

Specified by:
  `disconnect` in class `AbstractSockJsSession`
Throws:
  `IOException`