public class DefaultHandshakeHandler extends java.lang.Object implements HandshakeHandler
HandshakeHandler
.
A container-specific RequestUpgradeStrategy
is required since standard Java
WebSocket currently does not provide a way to initiate a WebSocket handshake.
Currently available are implementations for Tomcat and GlassFish.
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultHandshakeHandler.RequestUpgradeStrategyFactory |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
GUID |
protected Log |
logger |
private RequestUpgradeStrategy |
requestUpgradeStrategy |
private java.util.List<java.lang.String> |
supportedProtocols |
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(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler webSocketHandler)
Initiate the handshake.
|
java.lang.String[] |
getSupportedProtocols() |
protected java.lang.String[] |
getSupportedVerions() |
private java.lang.String |
getWebSocketKeyHash(java.lang.String key) |
protected void |
handleInvalidConnectHeader(ServerHttpRequest request,
ServerHttpResponse response) |
protected void |
handleInvalidUpgradeHeader(ServerHttpRequest request,
ServerHttpResponse response) |
protected void |
handleWebSocketVersionNotSupported(ServerHttpRequest request,
ServerHttpResponse response) |
protected boolean |
isValidOrigin(ServerHttpRequest request) |
protected boolean |
isWebSocketVersionSupported(ServerHttpRequest request) |
protected java.lang.String |
selectProtocol(java.util.List<java.lang.String> requestedProtocols) |
void |
setSupportedProtocols(java.lang.String... protocols) |
private static final java.lang.String GUID
protected Log logger
private java.util.List<java.lang.String> supportedProtocols
private final RequestUpgradeStrategy requestUpgradeStrategy
public DefaultHandshakeHandler()
RequestUpgradeStrategy
suitable for the runtime container.java.lang.IllegalStateException
- if no RequestUpgradeStrategy
can be found.public DefaultHandshakeHandler(RequestUpgradeStrategy upgradeStrategy)
RequestUpgradeStrategy
.upgradeStrategy
- the upgrade strategypublic void setSupportedProtocols(java.lang.String... protocols)
public java.lang.String[] getSupportedProtocols()
public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler webSocketHandler) throws java.io.IOException, HandshakeFailureException
HandshakeHandler
doHandshake
in interface HandshakeHandler
request
- the current requestresponse
- the current responsewebSocketHandler
- the handler to process WebSocket messages; see
PerConnectionWebSocketHandler
for providing a handler with
per-connection lifecycle.java.io.IOException
- thrown when accessing or setting the responseHandshakeFailureException
- 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 requirements of the
handshake request.protected void handleInvalidUpgradeHeader(ServerHttpRequest request, ServerHttpResponse response) throws java.io.IOException
java.io.IOException
protected void handleInvalidConnectHeader(ServerHttpRequest request, ServerHttpResponse response) throws java.io.IOException
java.io.IOException
protected boolean isWebSocketVersionSupported(ServerHttpRequest request)
protected java.lang.String[] getSupportedVerions()
protected void handleWebSocketVersionNotSupported(ServerHttpRequest request, ServerHttpResponse response)
protected boolean isValidOrigin(ServerHttpRequest request)
protected java.lang.String selectProtocol(java.util.List<java.lang.String> requestedProtocols)
private java.lang.String getWebSocketKeyHash(java.lang.String key) throws HandshakeFailureException
HandshakeFailureException