public class WebSocketTransportHandler extends AbstractTransportHandler implements SockJsSessionFactory, HandshakeHandler, Lifecycle, ServletContextAware
TransportHandler. Uses SockJsWebSocketHandler and
WebSocketServerSockJsSession to add SockJS processing.
Also implements HandshakeHandler to support raw WebSocket communication at
SockJS URL "/websocket".
logger, UTF8_CHARSET| Constructor and Description |
|---|
WebSocketTransportHandler(HandshakeHandler handshakeHandler) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkSessionType(SockJsSession session)
Check whether the type of the given session matches the transport type
of this
TransportHandler where session id and the transport type
are extracted from the SockJS URL. |
AbstractSockJsSession |
createSession(java.lang.String id,
WebSocketHandler handler,
java.util.Map<java.lang.String,java.lang.Object> attrs)
Create a new SockJS session.
|
boolean |
doHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler handler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Initiate the handshake.
|
HandshakeHandler |
getHandshakeHandler() |
TransportType |
getTransportType()
Return the transport type supported by this handler.
|
void |
handleRequest(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
SockJsSession wsSession)
Handle the given request and delegate messages to the provided
WebSocketHandler. |
boolean |
isRunning()
Check whether this component is currently running.
|
void |
setServletContext(ServletContext servletContext)
Set the
ServletContext that this object runs in. |
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.
|
getServiceConfig, initializepublic WebSocketTransportHandler(HandshakeHandler handshakeHandler)
public TransportType getTransportType()
TransportHandlergetTransportType in interface TransportHandlerpublic HandshakeHandler getHandshakeHandler()
public void setServletContext(ServletContext servletContext)
ServletContextAwareServletContext that this object runs in.
Invoked after population of normal bean properties but before an init
callback like InitializingBean's afterPropertiesSet or a
custom init-method. Invoked after ApplicationContextAware's
setApplicationContext.
setServletContext in interface ServletContextAwareservletContext - ServletContext object to be used by this objectInitializingBean.afterPropertiesSet(),
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)public void start()
LifecycleShould 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 LifecycleSmartLifecycle.isAutoStartup()public void stop()
LifecycleSmartLifecycle
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 LifecycleSmartLifecycle.stop(Runnable),
DisposableBean.destroy()public boolean isRunning()
LifecycleIn the case of a container, this will return true only if all
components that apply are currently running.
public boolean checkSessionType(SockJsSession session)
TransportHandlerTransportHandler where session id and the transport type
are extracted from the SockJS URL.checkSessionType in interface TransportHandlertrue if the session matches (and would therefore get
accepted by TransportHandler.handleRequest(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, org.springframework.web.socket.WebSocketHandler, org.springframework.web.socket.sockjs.transport.SockJsSession)), or false otherwisepublic AbstractSockJsSession createSession(java.lang.String id, WebSocketHandler handler, java.util.Map<java.lang.String,java.lang.Object> attrs)
SockJsSessionFactorycreateSession in interface SockJsSessionFactoryid - the ID of the sessionhandler - the underlying WebSocketHandlerattrs - handshake request specific attributesnullpublic void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException
TransportHandlerWebSocketHandler.handleRequest in interface TransportHandlerrequest - the current requestresponse - the current responsewsHandler - the target WebSocketHandler (never null)wsSession - the SockJS session (never null)SockJsException - raised when request processing fails as
explained in SockJsServicepublic boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, java.util.Map<java.lang.String,java.lang.Object> attributes) throws HandshakeFailureException
HandshakeHandlerdoHandshake in interface HandshakeHandlerrequest - the current requestresponse - the current responsehandler - the handler to process WebSocket messages; see
PerConnectionWebSocketHandler for providing a handler with
per-connection lifecycle.attributes - attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used.HandshakeFailureException - thrown when handshake processing failed to
complete due to an internal, unrecoverable error, i.e. a server error as
opposed to a failure to successfully negotiate the handshake.