public class WebSocketTransportHandler extends AbstractTransportHandler implements SockJsSessionFactory, HandshakeHandler
TransportHandler
. Uses SockJsWebSocketHandler
and
WebSocketServerSockJsSession
to add SockJS processing.
Also implements HandshakeHandler
to support raw WebSocket communication at
SockJS URL "/websocket".
Modifier and Type | Field and Description |
---|---|
private HandshakeHandler |
handshakeHandler |
logger, UTF8_CHARSET
Constructor and Description |
---|
WebSocketTransportHandler(HandshakeHandler handshakeHandler) |
Modifier and Type | Method and Description |
---|---|
AbstractSockJsSession |
createSession(java.lang.String sessionId,
WebSocketHandler handler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
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 . |
getServiceConfig, initialize
private final HandshakeHandler handshakeHandler
public WebSocketTransportHandler(HandshakeHandler handshakeHandler)
public TransportType getTransportType()
TransportHandler
getTransportType
in interface TransportHandler
public HandshakeHandler getHandshakeHandler()
public AbstractSockJsSession createSession(java.lang.String sessionId, WebSocketHandler handler, java.util.Map<java.lang.String,java.lang.Object> attributes)
SockJsSessionFactory
createSession
in interface SockJsSessionFactory
sessionId
- the ID of the sessionhandler
- the underlying WebSocketHandler
attributes
- handshake request specific attributesnull
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException
TransportHandler
WebSocketHandler
.handleRequest
in interface TransportHandler
request
- 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 SockJsService
public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, java.util.Map<java.lang.String,java.lang.Object> attributes) throws HandshakeFailureException
HandshakeHandler
doHandshake
in interface HandshakeHandler
request
- 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.