org.springframework.web.socket.sockjs.transport

## Class TransportHandlingSockJsService

- java.lang.Object
- - org.springframework.web.socket.sockjs.support.AbstractSockJsService
  - - org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService

- All Implemented Interfaces:
    SockJsService, SockJsServiceConfig
  Direct Known Subclasses:
    DefaultSockJsService

      public class TransportHandlingSockJsService
      extends AbstractSockJsService
      implements SockJsServiceConfig

  A basic implementation of `SockJsService` with support for SPI-based transport handling and session management.

  Based on the `TransportHandler` SPI. `TransportHandler`s may additionally implement the `SockJsSessionFactory` and `HandshakeHandler` interfaces.

  See the `AbstractSockJsService` base class for important details on request mapping.

  Since:
    4.0
  Author:
    Rossen Stoyanchev, Juergen Hoeller

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.socket.sockjs.support.AbstractSockJsService

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers)` Create a TransportHandlingSockJsService with given `handler` types.
    `TransportHandlingSockJsService(TaskScheduler scheduler, TransportHandler... handlers)` Create a TransportHandlingSockJsService with given `handler` types.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<HandshakeInterceptor>` | `getHandshakeInterceptors()` Return the configured WebSocket handshake request interceptors.
    `SockJsMessageCodec` | `getMessageCodec()` The codec to use for encoding and decoding SockJS messages.
    `Map<TransportType,TransportHandler>` | `getTransportHandlers()` Return the registered handlers per transport type.
    `protected void` | `handleRawWebSocketRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler)` Handle request for raw WebSocket communication, i.e.
    `protected void` | `handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport)` Handle a SockJS session URL (i.e.
    `void` | `setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)` Configure one or more WebSocket handshake request interceptors.
    `void` | `setMessageCodec(SockJsMessageCodec messageCodec)` The codec to use for encoding and decoding SockJS messages.

    - ### Methods inherited from class org.springframework.web.socket.sockjs.support.AbstractSockJsService

      `addCacheHeaders, addCorsHeaders, addNoCacheHeaders, getDisconnectDelay, getHeartbeatTime, getHttpMessageCacheSize, getName, getSockJsClientLibraryUrl, getStreamBytesLimit, getTaskScheduler, handleRequest, isSessionCookieNeeded, isWebSocketEnabled, sendMethodNotAllowed, setDisconnectDelay, setHeartbeatTime, setHttpMessageCacheSize, setName, setSessionCookieNeeded, setSockJsClientLibraryUrl, setStreamBytesLimit, setWebSocketEnabled, validateRequest`

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

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

    - ### Methods inherited from interface org.springframework.web.socket.sockjs.transport.SockJsServiceConfig

      `getHeartbeatTime, getHttpMessageCacheSize, getStreamBytesLimit, getTaskScheduler`

- - ### Constructor Detail

    - #### TransportHandlingSockJsService

          public TransportHandlingSockJsService(TaskScheduler scheduler,
                                                TransportHandler... handlers)

      Create a TransportHandlingSockJsService with given `handler` types.
      Parameters:
        `scheduler` - a task scheduler for heart-beat messages and removing timed-out sessions; the provided TaskScheduler should be declared as a Spring bean to ensure it gets initialized at start-up and shuts down when the application stops
        `handlers` - one or more `TransportHandler` implementations to use

    - #### TransportHandlingSockJsService

          public TransportHandlingSockJsService(TaskScheduler scheduler,
                                                Collection<TransportHandler> handlers)

      Create a TransportHandlingSockJsService with given `handler` types.
      Parameters:
        `scheduler` - a task scheduler for heart-beat messages and removing timed-out sessions; the provided TaskScheduler should be declared as a Spring bean to ensure it gets initialized at start-up and shuts down when the application stops
        `handlers` - one or more `TransportHandler` implementations to use

  - ### Method Detail

    - #### getTransportHandlers

          public Map<TransportType,TransportHandler> getTransportHandlers()

      Return the registered handlers per transport type.

    - #### setMessageCodec

          public void setMessageCodec(SockJsMessageCodec messageCodec)

      The codec to use for encoding and decoding SockJS messages.

    - #### getMessageCodec

          public SockJsMessageCodec getMessageCodec()

      Description copied from interface: `SockJsServiceConfig`
      The codec to use for encoding and decoding SockJS messages.
      Specified by:
        `getMessageCodec` in interface `SockJsServiceConfig`

    - #### setHandshakeInterceptors

          public void setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)

      Configure one or more WebSocket handshake request interceptors.

    - #### getHandshakeInterceptors

          public List<HandshakeInterceptor> getHandshakeInterceptors()

      Return the configured WebSocket handshake request interceptors.

    - #### handleRawWebSocketRequest

          protected void handleRawWebSocketRequest(ServerHttpRequest request,
                                                   ServerHttpResponse response,
                                                   WebSocketHandler handler)
                                            throws IOException

      Description copied from class: `AbstractSockJsService`
      Handle request for raw WebSocket communication, i.e. without any SockJS message framing.
      Specified by:
        `handleRawWebSocketRequest` in class `AbstractSockJsService`
      Throws:
        `IOException`

    - #### handleTransportRequest

          protected void handleTransportRequest(ServerHttpRequest request,
                                                ServerHttpResponse response,
                                                WebSocketHandler handler,
                                                String sessionId,
                                                String transport)
                                         throws SockJsException

      Description copied from class: `AbstractSockJsService`
      Handle a SockJS session URL (i.e. transport-specific request).
      Specified by:
        `handleTransportRequest` in class `AbstractSockJsService`
      Throws:
        `SockJsException`