Class TransportHandlingSockJsService
java.lang.Object
org.springframework.web.socket.sockjs.support.AbstractSockJsService
org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService
- All Implemented Interfaces:
org.springframework.context.Lifecycle
,org.springframework.web.cors.CorsConfigurationSource
,SockJsService
,SockJsServiceConfig
- Direct Known Subclasses:
DefaultSockJsService
public class TransportHandlingSockJsService
extends AbstractSockJsService
implements SockJsServiceConfig, org.springframework.context.Lifecycle
A basic implementation of
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
ConstructorDescriptionTransportHandlingSockJsService
(org.springframework.scheduling.TaskScheduler scheduler, Collection<TransportHandler> handlers) Create a TransportHandlingSockJsService with givenhandler
types.TransportHandlingSockJsService
(org.springframework.scheduling.TaskScheduler scheduler, TransportHandler... handlers) Create a TransportHandlingSockJsService with givenhandler
types. -
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 void
handleRawWebSocketRequest
(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, WebSocketHandler handler) Handle request for raw WebSocket communication, i.e.protected void
handleTransportRequest
(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) Handle a SockJS session URL (i.e.boolean
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()
void
stop()
protected boolean
validateRequest
(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, shouldSuppressCors
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 Details
-
TransportHandlingSockJsService
public TransportHandlingSockJsService(org.springframework.scheduling.TaskScheduler scheduler, TransportHandler... handlers) Create a TransportHandlingSockJsService with givenhandler
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 stopshandlers
- one or moreTransportHandler
implementations to use
-
TransportHandlingSockJsService
public TransportHandlingSockJsService(org.springframework.scheduling.TaskScheduler scheduler, Collection<TransportHandler> handlers) Create a TransportHandlingSockJsService with givenhandler
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 stopshandlers
- one or moreTransportHandler
implementations 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:SockJsServiceConfig
The codec to use for encoding and decoding SockJS messages.- Specified by:
getMessageCodec
in interfaceSockJsServiceConfig
-
setHandshakeInterceptors
Configure one or more WebSocket handshake request interceptors. -
getHandshakeInterceptors
Return the configured WebSocket handshake request interceptors. -
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
handleRawWebSocketRequest
protected void handleRawWebSocketRequest(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.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 classAbstractSockJsService
- Throws:
IOException
-
handleTransportRequest
protected void handleTransportRequest(org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.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 classAbstractSockJsService
- Throws:
SockJsException
-
validateRequest
- Overrides:
validateRequest
in classAbstractSockJsService
-