public class DefaultHandshakeHandler extends Object implements HandshakeHandler
HandshakeHandler implementation. Performs initial validation of the
WebSocket handshake request -- possibly rejecting it through the appropriate HTTP
status code -- while also allowing sub-classes to override various parts of the
negotiation process (e.g. origin validation, sub-protocol negotiation, etc).
If the negotiation succeeds, the actual upgrade is delegated to a server-specific
RequestUpgradeStrategy, which will update the response as necessary and
initialize the WebSocket. Currently supported servers are Tomcat 7 and 8, Jetty 9, and
Glassfish 4.
| Constructor and Description |
|---|
DefaultHandshakeHandler()
Default constructor that auto-detects and instantiates a
RequestUpgradeStrategy suitable for the runtime container. |
DefaultHandshakeHandler(RequestUpgradeStrategy upgradeStrategy)
A constructor that accepts a runtime specific
RequestUpgradeStrategy. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
doHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
WebSocketHandler wsHandler,
Map<String,Object> attributes)
Initiate the handshake.
|
String[] |
getSupportedProtocols()
Return the list of supported sub-protocols.
|
protected String[] |
getSupportedVerions() |
protected void |
handleInvalidConnectHeader(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response) |
protected void |
handleInvalidUpgradeHeader(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response) |
protected void |
handleWebSocketVersionNotSupported(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response) |
protected boolean |
isValidOrigin(org.springframework.http.server.ServerHttpRequest request) |
protected boolean |
isWebSocketVersionSupported(org.springframework.http.server.ServerHttpRequest request) |
protected String |
selectProtocol(List<String> requestedProtocols) |
void |
setSupportedProtocols(String... protocols)
Use this property to configure a list of sub-protocols that are supported.
|
protected Log logger
public DefaultHandshakeHandler()
RequestUpgradeStrategy suitable for the runtime container.IllegalStateException - if no RequestUpgradeStrategy can be found.public DefaultHandshakeHandler(RequestUpgradeStrategy upgradeStrategy)
RequestUpgradeStrategy.upgradeStrategy - the upgrade strategypublic void setSupportedProtocols(String... protocols)
public String[] getSupportedProtocols()
public final boolean doHandshake(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response,
WebSocketHandler wsHandler,
Map<String,Object> attributes)
throws HandshakeFailureException
HandshakeHandlerdoHandshake in interface HandshakeHandlerrequest - the current requestresponse - the current responsewsHandler - the handler to process WebSocket messages; see
PerConnectionWebSocketHandler for providing a handler with
per-connection lifecycle.attributes - handshake request specific attributes to be set on the WebSocket
session and thus made available to the WebSocketHandlerHandshakeFailureException - 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.protected void handleInvalidUpgradeHeader(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response)
throws IOException
IOExceptionprotected void handleInvalidConnectHeader(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response)
throws IOException
IOExceptionprotected boolean isWebSocketVersionSupported(org.springframework.http.server.ServerHttpRequest request)
protected String[] getSupportedVerions()
protected void handleWebSocketVersionNotSupported(org.springframework.http.server.ServerHttpRequest request,
org.springframework.http.server.ServerHttpResponse response)
protected boolean isValidOrigin(org.springframework.http.server.ServerHttpRequest request)