Class TransportHandlingSockJsService
- All Implemented Interfaces:
Lifecycle,CorsConfigurationSource,SockJsService,SockJsServiceConfig
- Direct Known Subclasses:
DefaultSockJsService
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.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
-
Field Summary
Fields inherited from class org.springframework.web.socket.sockjs.support.AbstractSockJsService
corsConfiguration, logger -
Constructor Summary
ConstructorsConstructorDescriptionTransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) Create a TransportHandlingSockJsService with givenhandlertypes.TransportHandlingSockJsService(TaskScheduler scheduler, TransportHandler... handlers) Create a TransportHandlingSockJsService with givenhandlertypes. -
Method Summary
Modifier and TypeMethodDescriptionReturn the configured WebSocket handshake request interceptors.The codec to use for encoding and decoding SockJS messages.Return the registered handlers per transport type.protected voidhandleRawWebSocketRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler) Handle request for raw WebSocket communication, i.e.protected voidhandleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) Handle a SockJS session URL (i.e.booleanCheck whether this component is currently running.voidsetHandshakeInterceptors(List<HandshakeInterceptor> interceptors) Configure one or more WebSocket handshake request interceptors.voidsetMessageCodec(SockJsMessageCodec messageCodec) The codec to use for encoding and decoding SockJS messages.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.protected booleanvalidateRequest(String serverId, String sessionId, String transport) Methods inherited from class org.springframework.web.socket.sockjs.support.AbstractSockJsService
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, shouldSuppressCorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.socket.sockjs.transport.SockJsServiceConfig
getHeartbeatTime, getHttpMessageCacheSize, getStreamBytesLimit, getTaskScheduler
-
Constructor Details
-
TransportHandlingSockJsService
Create a TransportHandlingSockJsService with givenhandlertypes.- 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 stopshandlers- one or moreTransportHandlerimplementations to use
-
TransportHandlingSockJsService
public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) Create a TransportHandlingSockJsService with givenhandlertypes.- 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 stopshandlers- one or moreTransportHandlerimplementations to use
-
-
Method Details
-
getTransportHandlers
Return the registered handlers per transport type. -
setMessageCodec
The codec to use for encoding and decoding SockJS messages. -
getMessageCodec
Description copied from interface:SockJsServiceConfigThe codec to use for encoding and decoding SockJS messages.- Specified by:
getMessageCodecin interfaceSockJsServiceConfig
-
setHandshakeInterceptors
Configure one or more WebSocket handshake request interceptors. -
getHandshakeInterceptors
Return the configured WebSocket handshake request interceptors. -
start
public void start()Description copied from interface:LifecycleStart 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.
-
stop
public void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans 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.
-
isRunning
public boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running. -
handleRawWebSocketRequest
protected void handleRawWebSocketRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler) throws IOException Description copied from class:AbstractSockJsServiceHandle request for raw WebSocket communication, i.e. without any SockJS message framing.- Specified by:
handleRawWebSocketRequestin classAbstractSockJsService- Throws:
IOException
-
handleTransportRequest
protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) throws SockJsException Description copied from class:AbstractSockJsServiceHandle a SockJS session URL (i.e. transport-specific request).- Specified by:
handleTransportRequestin classAbstractSockJsService- Throws:
SockJsException
-
validateRequest
- Overrides:
validateRequestin classAbstractSockJsService
-