Top Description Fields Constructors Methods
org.springframework.web.socket.sockjs.transport

public Class TransportHandlingSockJsService

extends AbstractSockJsService
implements SockJsServiceConfig, Lifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.Lifecycle, org.springframework.web.socket.sockjs.transport.SockJsServiceConfig
Known Direct Subclasses
org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService
Imports
java.io.IOException, java.security.Principal, java.time.Duration, java.util.ArrayList, .Arrays, .Collection, .Collections, .EnumMap, .HashMap, .List, .Map, java.util.concurrent.ConcurrentHashMap, .ScheduledFuture, org.springframework.context.Lifecycle, org.springframework.core.log.LogFormatUtils, org.springframework.http.HttpMethod, .HttpStatus, .HttpStatusCode, org.springframework.http.server.ServerHttpRequest, .ServerHttpResponse, .ServletServerHttpResponse, org.springframework.lang.Nullable, org.springframework.scheduling.TaskScheduler, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, org.springframework.web.socket.WebSocketHandler, org.springframework.web.socket.server.HandshakeFailureException, .HandshakeHandler, .HandshakeInterceptor, org.springframework.web.socket.server.support.HandshakeInterceptorChain, org.springframework.web.socket.sockjs.SockJsException, org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec, .SockJsMessageCodec, org.springframework.web.socket.sockjs.support.AbstractSockJsService

A basic implementation of org.springframework.web.socket.sockjs.SockJsService with support for SPI-based transport handling and session management.

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

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

Authors
Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
Since
4.0

Field Summary

Modifier and TypeField and Description
private final Map<TransportType, TransportHandler>
private final List<HandshakeInterceptor>
private static final boolean
private SockJsMessageCodec
private volatile boolean
private ScheduledFuture<?>
private final Map<String, SockJsSession>
Inherited from org.springframework.web.socket.sockjs.support.AbstractSockJsService:
corsConfigurationlogger

Constructor Summary

AccessConstructor and Description
public
TransportHandlingSockJsService(TaskScheduler
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
scheduler
,
TransportHandler...
one or more TransportHandler implementations to use
handlers
)

Create a TransportHandlingSockJsService with given handler types.

public
TransportHandlingSockJsService(TaskScheduler
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
scheduler
,
Collection<TransportHandler>
one or more TransportHandler implementations to use
handlers
)

Create a TransportHandlingSockJsService with given handler types.

Method Summary

Modifier and TypeMethod and Description
private SockJsSession
createSockJsSession(String sessionId, SockJsSessionFactory sessionFactory, WebSocketHandler handler, Map<String, Object> attributes)

public List<HandshakeInterceptor>
getHandshakeInterceptors()

Return the configured WebSocket handshake request interceptors.

public SockJsMessageCodec
getMessageCodec()

Implements org.springframework.web.socket.sockjs.transport.SockJsServiceConfig.getMessageCodec.

The codec to use for encoding and decoding SockJS messages.

public Map<TransportType, TransportHandler>
getTransportHandlers()

Return the registered handlers per transport type.

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

Implements abstract org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleRawWebSocketRequest.

Handle request for raw WebSocket communication, i.e. without any SockJS message framing.

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

Implements abstract org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleTransportRequest.

Handle a SockJS session URL (i.e. transport-specific request).

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

private void
public void
setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)

Configure one or more WebSocket handshake request interceptors.

public void
setMessageCodec(SockJsMessageCodec messageCodec)

The codec to use for encoding and decoding SockJS messages.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

protected boolean
Inherited from org.springframework.web.socket.sockjs.support.AbstractSockJsService:
addCacheHeadersaddNoCacheHeaderscheckOrigingetAllowedOriginPatternsgetAllowedOriginsgetCorsConfigurationgetDisconnectDelaygetHeartbeatTimegetHttpMessageCacheSizegetNamegetSockJsClientLibraryUrlgetStreamBytesLimitgetTaskSchedulerhandleRequestisSessionCookieNeededisWebSocketEnabledsendMethodNotAllowedsetAllowedOriginPatternssetAllowedOriginssetDisconnectDelaysetHeartbeatTimesetHttpMessageCacheSizesetNamesetSessionCookieNeededsetSockJsClientLibraryUrlsetStreamBytesLimitsetSuppressCorssetWebSocketEnabledshouldSuppressCors

Field Detail

handlersback to summary
private final Map<TransportType, TransportHandler> handlers
interceptorsback to summary
private final List<HandshakeInterceptor> interceptors
jackson2Presentback to summary
private static final boolean jackson2Present
messageCodecback to summary
private SockJsMessageCodec messageCodec
Annotations
@Nullable
runningback to summary
private volatile boolean running
sessionCleanupTaskback to summary
private ScheduledFuture<?> sessionCleanupTask
Annotations
@Nullable
sessionsback to summary
private final Map<String, SockJsSession> sessions

Constructor Detail

TransportHandlingSockJsServiceback to summary
public TransportHandlingSockJsService(TaskScheduler scheduler, TransportHandler... handlers)

Create a TransportHandlingSockJsService with given handler types.

Parameters
scheduler:TaskScheduler

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:TransportHandler[]

one or more TransportHandler implementations to use

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

Create a TransportHandlingSockJsService with given handler types.

Parameters
scheduler:TaskScheduler

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:Collection<TransportHandler>

one or more TransportHandler implementations to use

Method Detail

createSockJsSessionback to summary
private SockJsSession createSockJsSession(String sessionId, SockJsSessionFactory sessionFactory, WebSocketHandler handler, Map<String, Object> attributes)
getHandshakeInterceptorsback to summary
public List<HandshakeInterceptor> getHandshakeInterceptors()

Return the configured WebSocket handshake request interceptors.

getMessageCodecback to summary
public SockJsMessageCodec getMessageCodec()

Implements org.springframework.web.socket.sockjs.transport.SockJsServiceConfig.getMessageCodec.

Doc from org.springframework.web.socket.sockjs.transport.SockJsServiceConfig.getMessageCodec.

The codec to use for encoding and decoding SockJS messages.

Annotations
@Override
getTransportHandlersback to summary
public Map<TransportType, TransportHandler> getTransportHandlers()

Return the registered handlers per transport type.

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

Implements abstract org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleRawWebSocketRequest.

Doc from org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleRawWebSocketRequest.

Handle request for raw WebSocket communication, i.e. without any SockJS message framing.

Annotations
@Override
handleTransportRequestback to summary
protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) throws SockJsException

Implements abstract org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleTransportRequest.

Doc from org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleTransportRequest.

Handle a SockJS session URL (i.e. transport-specific request).

Annotations
@Override
isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

In the case of a container, this will return true only if all components that apply are currently running.

Returns:boolean

whether the component is currently running

Annotations
@Override
scheduleSessionTaskback to summary
private void scheduleSessionTask()
setHandshakeInterceptorsback to summary
public void setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)

Configure one or more WebSocket handshake request interceptors.

setMessageCodecback to summary
public void setMessageCodec(SockJsMessageCodec messageCodec)

The codec to use for encoding and decoding SockJS messages.

startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

Start this component.

Should not throw an exception if the component is already running.

In the case of a container, this will propagate the start signal to all components that apply.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

Should not throw an exception if the component is not running (not started yet).

In the case of a container, this will propagate the stop signal to all components that apply.

Annotations
@Override
validateRequestback to summary
protected boolean validateRequest(String serverId, String sessionId, String transport)

Overrides org.springframework.web.socket.sockjs.support.AbstractSockJsService.validateRequest.

Annotations
@Override