public class TransportHandlingSockJsService extends AbstractSockJsService implements SockJsServiceConfig, Lifecycle
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.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<TransportType,TransportHandler> |
handlers |
private java.util.List<HandshakeInterceptor> |
interceptors |
private static boolean |
jackson2Present |
private SockJsMessageCodec |
messageCodec |
private boolean |
running |
private java.util.concurrent.ScheduledFuture<?> |
sessionCleanupTask |
private java.util.Map<java.lang.String,SockJsSession> |
sessions |
allowedOrigins, logger
Constructor and Description |
---|
TransportHandlingSockJsService(TaskScheduler scheduler,
java.util.Collection<TransportHandler> handlers)
Create a TransportHandlingSockJsService with given
handler types. |
TransportHandlingSockJsService(TaskScheduler scheduler,
TransportHandler... handlers)
Create a TransportHandlingSockJsService with given
handler types. |
Modifier and Type | Method and Description |
---|---|
private SockJsSession |
createSockJsSession(java.lang.String sessionId,
SockJsSessionFactory sessionFactory,
WebSocketHandler handler,
java.util.Map<java.lang.String,java.lang.Object> attributes) |
java.util.List<HandshakeInterceptor> |
getHandshakeInterceptors()
Return the configured WebSocket handshake request interceptors.
|
SockJsMessageCodec |
getMessageCodec()
The codec to use for encoding and decoding SockJS messages.
|
java.util.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,
java.lang.String sessionId,
java.lang.String transport)
Handle a SockJS session URL (i.e.
|
boolean |
isRunning()
Check whether this component is currently running.
|
private void |
scheduleSessionTask() |
void |
setHandshakeInterceptors(java.util.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.
|
void |
start()
Start this component.
|
void |
stop()
Stop this component, typically in a synchronous fashion, such that the component is
fully stopped upon return of this method.
|
protected boolean |
validateRequest(java.lang.String serverId,
java.lang.String sessionId,
java.lang.String transport) |
addCacheHeaders, addNoCacheHeaders, checkOrigin, getAllowedOrigins, getCorsConfiguration, getDisconnectDelay, getHeartbeatTime, getHttpMessageCacheSize, getName, getSockJsClientLibraryUrl, getStreamBytesLimit, getTaskScheduler, handleRequest, isSessionCookieNeeded, isWebSocketEnabled, sendMethodNotAllowed, setAllowedOrigins, setDisconnectDelay, setHeartbeatTime, setHttpMessageCacheSize, setName, setSessionCookieNeeded, setSockJsClientLibraryUrl, setStreamBytesLimit, setSuppressCors, setWebSocketEnabled, shouldSuppressCors
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHeartbeatTime, getHttpMessageCacheSize, getStreamBytesLimit, getTaskScheduler
private static final boolean jackson2Present
private final java.util.Map<TransportType,TransportHandler> handlers
@Nullable private SockJsMessageCodec messageCodec
private final java.util.List<HandshakeInterceptor> interceptors
private final java.util.Map<java.lang.String,SockJsSession> sessions
@Nullable private java.util.concurrent.ScheduledFuture<?> sessionCleanupTask
private boolean running
public TransportHandlingSockJsService(TaskScheduler scheduler, TransportHandler... handlers)
handler
types.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 stopshandlers
- one or more TransportHandler
implementations to usepublic TransportHandlingSockJsService(TaskScheduler scheduler, java.util.Collection<TransportHandler> handlers)
handler
types.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 stopshandlers
- one or more TransportHandler
implementations to usepublic java.util.Map<TransportType,TransportHandler> getTransportHandlers()
public void setMessageCodec(SockJsMessageCodec messageCodec)
public SockJsMessageCodec getMessageCodec()
SockJsServiceConfig
getMessageCodec
in interface SockJsServiceConfig
public void setHandshakeInterceptors(@Nullable java.util.List<HandshakeInterceptor> interceptors)
public java.util.List<HandshakeInterceptor> getHandshakeInterceptors()
public void start()
Lifecycle
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.
start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
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, only destroy methods will be called.
Should not throw an exception if the component isn't started yet.
In the case of a container, this will propagate the stop signal to all components that apply.
stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
protected void handleRawWebSocketRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler) throws java.io.IOException
AbstractSockJsService
handleRawWebSocketRequest
in class AbstractSockJsService
java.io.IOException
protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, java.lang.String sessionId, java.lang.String transport) throws SockJsException
AbstractSockJsService
handleTransportRequest
in class AbstractSockJsService
SockJsException
protected boolean validateRequest(java.lang.String serverId, java.lang.String sessionId, java.lang.String transport)
validateRequest
in class AbstractSockJsService
private SockJsSession createSockJsSession(java.lang.String sessionId, SockJsSessionFactory sessionFactory, WebSocketHandler handler, java.util.Map<java.lang.String,java.lang.Object> attributes)
private void scheduleSessionTask()