public class TransportHandlingSockJsService extends AbstractSockJsService implements SockJsServiceConfig, Lifecycle
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.
corsConfiguration, logger
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. |
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.
|
boolean |
isRunning()
Check whether this component is currently running.
|
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.
|
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(String serverId,
String sessionId,
String transport) |
addCacheHeaders, addNoCacheHeaders, checkOrigin, getAllowedOriginPatterns, getAllowedOrigins, getCorsConfiguration, getDisconnectDelay, getHeartbeatTime, getHttpMessageCacheSize, getName, getSockJsClientLibraryUrl, getStreamBytesLimit, getTaskScheduler, handleRequest, isSessionCookieNeeded, isWebSocketEnabled, sendMethodNotAllowed, setAllowedOriginPatterns, 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
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, 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 Map<TransportType,TransportHandler> getTransportHandlers()
public void setMessageCodec(SockJsMessageCodec messageCodec)
public SockJsMessageCodec getMessageCodec()
SockJsServiceConfig
getMessageCodec
in interface SockJsServiceConfig
public void setHandshakeInterceptors(@Nullable List<HandshakeInterceptor> interceptors)
public 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, 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.
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 IOException
AbstractSockJsService
handleRawWebSocketRequest
in class AbstractSockJsService
IOException
protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) throws SockJsException
AbstractSockJsService
handleTransportRequest
in class AbstractSockJsService
SockJsException
protected boolean validateRequest(String serverId, String sessionId, String transport)
validateRequest
in class AbstractSockJsService