org.springframework.web.socket.sockjs.transport.handler

## Class WebSocketTransportHandler

- java.lang.Object
- - org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler
  - - org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler

- All Implemented Interfaces:
    HandshakeHandler, SockJsSessionFactory, TransportHandler

      public class WebSocketTransportHandler
      extends AbstractTransportHandler
      implements SockJsSessionFactory, HandshakeHandler

  WebSocket-based `TransportHandler`. Uses `SockJsWebSocketHandler` and `WebSocketServerSockJsSession` to add SockJS processing.

  Also implements `HandshakeHandler` to support raw WebSocket communication at SockJS URL "/websocket".

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler

      `logger, UTF8_CHARSET`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebSocketTransportHandler(HandshakeHandler handshakeHandler)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `AbstractSockJsSession` | `createSession(String sessionId, WebSocketHandler handler, Map<String,Object> attributes)` Create a new SockJS session.
    `boolean` | `doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, Map<String,Object> attributes)` Initiate the handshake.
    `HandshakeHandler` | `getHandshakeHandler()`
    `TransportType` | `getTransportType()` Return the transport type supported by this handler.
    `void` | `handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession)` Handle the given request and delegate messages to the provided `WebSocketHandler`.

    - ### Methods inherited from class org.springframework.web.socket.sockjs.transport.handler.AbstractTransportHandler

      `getServiceConfig, initialize`

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

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

- - ### Constructor Detail

    - #### WebSocketTransportHandler

          public WebSocketTransportHandler(HandshakeHandler handshakeHandler)

  - ### Method Detail

    - #### getTransportType

          public TransportType getTransportType()

      Description copied from interface: `TransportHandler`
      Return the transport type supported by this handler.
      Specified by:
        `getTransportType` in interface `TransportHandler`

    - #### getHandshakeHandler

          public HandshakeHandler getHandshakeHandler()

    - #### createSession

          public AbstractSockJsSession createSession(String sessionId,
                                                     WebSocketHandler handler,
                                                     Map<String,Object> attributes)

      Description copied from interface: `SockJsSessionFactory`
      Create a new SockJS session.
      Specified by:
        `createSession` in interface `SockJsSessionFactory`
      Parameters:
        `sessionId` - the ID of the session
        `handler` - the underlying `WebSocketHandler`
        `attributes` - handshake request specific attributes
      Returns:
        a new session, never `null`

    - #### handleRequest

          public void handleRequest(ServerHttpRequest request,
                                    ServerHttpResponse response,
                                    WebSocketHandler wsHandler,
                                    SockJsSession wsSession)
                             throws SockJsException

      Description copied from interface: `TransportHandler`
      Handle the given request and delegate messages to the provided `WebSocketHandler`.
      Specified by:
        `handleRequest` in interface `TransportHandler`
      Parameters:
        `request` - the current request
        `response` - the current response
        `wsHandler` - the target WebSocketHandler (never `null`)
        `wsSession` - the SockJS session (never `null`)
      Throws:
        `SockJsException` - raised when request processing fails as explained in `SockJsService`

    - #### doHandshake

          public boolean doHandshake(ServerHttpRequest request,
                                     ServerHttpResponse response,
                                     WebSocketHandler handler,
                                     Map<String,Object> attributes)
                              throws HandshakeFailureException

      Description copied from interface: `HandshakeHandler`
      Initiate the handshake.
      Specified by:
        `doHandshake` in interface `HandshakeHandler`
      Parameters:
        `request` - the current request
        `response` - the current response
        `handler` - the handler to process WebSocket messages; see `PerConnectionWebSocketHandler` for providing a handler with per-connection lifecycle.
        `attributes` - attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
      Returns:
        whether the handshake negotiation was successful or not. In either case the response status, headers, and body will have been updated to reflect the result of the negotiation
      Throws:
        `HandshakeFailureException` - thrown when handshake processing failed to complete due to an internal, unrecoverable error, i.e. a server error as opposed to a failure to successfully negotiate the handshake.