HandshakeHandler implementations, independent of the Servlet API.
Performs initial validation of the WebSocket handshake request - possibly rejecting it through the appropriate HTTP status code - while also allowing its subclasses to override various parts of the negotiation process (e.g. origin validation, sub-protocol negotiation, extensions negotiation, etc).
If the negotiation succeeds, the actual upgrade is delegated to a server-specific
org., which will update
the response as necessary and initialize the WebSocket.
org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy , org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy , org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy , org.springframework.web.socket.server.standard.GlassFishRequestUpgradeStrategy
| Modifier and Type | Class and Description |
|---|---|
| private static class | AbstractHandshakeHandler.
Inner class to avoid a reachable dependency on Tyrus API. |
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean | |
| private static final boolean | |
| protected final Log | |
| private final RequestUpgradeStrategy | |
| private volatile boolean | |
| private final List | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean |
| Access | Constructor and Description |
|---|---|
| protected | AbstractHandshakeHandler()
Default constructor that auto-detects and instantiates a
|
| protected | AbstractHandshakeHandler(RequestUpgradeStrategy
the upgrade strategy to use requestUpgradeStrategy)A constructor that accepts a runtime-specific |
| Modifier and Type | Method and Description |
|---|---|
| protected final List | Returns: a list of supported protocols, or an empty list if none availablethe handler to check handler)Determine the sub-protocols supported by the given WebSocketHandler by
checking whether it is an instance of |
| protected Principal | Returns: the user for the WebSocket session, ornull if not availablethe handshake request request, WebSocketHandler the WebSocket handler that will handle messages wsHandler, Map<String, Object> handshake attributes to pass to the WebSocket session attributes)A method that can be used to associate a user with the WebSocket session in the process of being established. |
| public final boolean | doHandshake(ServerHttpRequest
the current request request, ServerHttpResponse the current response response, WebSocketHandler the handler to process WebSocket messages; see
wsHandler, Map<String, Object> PerConnectionWebSocketHandler for providing a handler with
per-connection lifecycle.the attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used. attributes)Implements org. Initiate the handshake. |
| protected void | |
| protected void | |
| protected List | Returns: the selected extensions or an empty listthe current request request, List<WebSocketExtension> the list of extensions requested by the client requestedExtensions, List<WebSocketExtension> the list of extensions supported by the server supportedExtensions)Filter the list of requested WebSocket extensions. |
| public RequestUpgradeStrategy | |
| public String[] | |
| protected String[] | |
| protected void | |
| protected void | |
| protected void | |
| private static RequestUpgradeStrategy | |
| public boolean | isRunning()
Implements org. Check whether this component is currently running. |
| protected boolean | isValidOrigin(ServerHttpRequest request)
Return whether the request |
| protected boolean | |
| protected String | Returns: the selected protocols ornullthe requested sub-protocols requestedProtocols, WebSocketHandler the WebSocketHandler that will be used webSocketHandler)Perform the sub-protocol negotiation based on requested and supported sub-protocols. |
| public void | setSupportedProtocols(String... protocols)
Use this property to configure the list of supported sub-protocols. |
| public void | |
| public void | stop()
Implements org. Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. |
| glassfishWsPresent | back to summary |
|---|---|
| private static final boolean glassfishWsPresent | |
| jettyWsPresent | back to summary |
|---|---|
| private static final boolean jettyWsPresent | |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| requestUpgradeStrategy | back to summary |
|---|---|
| private final RequestUpgradeStrategy requestUpgradeStrategy | |
| running | back to summary |
|---|---|
| private volatile boolean running | |
| supportedProtocols | back to summary |
|---|---|
| private final List<String> supportedProtocols | |
| tomcatWsPresent | back to summary |
|---|---|
| private static final boolean tomcatWsPresent | |
| undertowWsPresent | back to summary |
|---|---|
| private static final boolean undertowWsPresent | |
| weblogicWsPresent | back to summary |
|---|---|
| private static final boolean weblogicWsPresent | |
| websphereWsPresent | back to summary |
|---|---|
| private static final boolean websphereWsPresent | |
| AbstractHandshakeHandler | back to summary |
|---|---|
| protected AbstractHandshakeHandler() Default constructor that auto-detects and instantiates a
| |
| AbstractHandshakeHandler | back to summary |
|---|---|
| protected AbstractHandshakeHandler(RequestUpgradeStrategy requestUpgradeStrategy) A constructor that accepts a runtime-specific
| |
| determineHandlerSupportedProtocols | back to summary |
|---|---|
| protected final List Determine the sub-protocols supported by the given WebSocketHandler by
checking whether it is an instance of
| |
| determineUser | back to summary |
|---|---|
| protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) A method that can be used to associate a user with the WebSocket session
in the process of being established. The default implementation calls
Subclasses can provide custom logic for associating a user with a session, for example for assigning a name to anonymous users (i.e. not fully authenticated).
| |
| doHandshake | back to summary |
|---|---|
| public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException Implements org. Doc from org. Initiate the handshake.
| |
| doStart | back to summary |
|---|---|
| protected void doStart() | |
| doStop | back to summary |
|---|---|
| protected void doStop() | |
| filterRequestedExtensions | back to summary |
|---|---|
| protected List Filter the list of requested WebSocket extensions. As of 4.1, the default implementation of this method filters the list to leave only extensions that are both requested and supported.
| |
| getRequestUpgradeStrategy | back to summary |
|---|---|
| public RequestUpgradeStrategy getRequestUpgradeStrategy() Return the | |
| getSupportedProtocols | back to summary |
|---|---|
| public String[] getSupportedProtocols() Return the list of supported sub-protocols. | |
| getSupportedVersions | back to summary |
|---|---|
| protected String[] getSupportedVersions() | |
| handleInvalidConnectHeader | back to summary |
|---|---|
| protected void handleInvalidConnectHeader(ServerHttpRequest request, ServerHttpResponse response) throws IOException | |
| handleInvalidUpgradeHeader | back to summary |
|---|---|
| protected void handleInvalidUpgradeHeader(ServerHttpRequest request, ServerHttpResponse response) throws IOException | |
| handleWebSocketVersionNotSupported | back to summary |
|---|---|
| protected void handleWebSocketVersionNotSupported(ServerHttpRequest request, ServerHttpResponse response) | |
| initRequestUpgradeStrategy | back to summary |
|---|---|
| private static RequestUpgradeStrategy initRequestUpgradeStrategy() | |
| isRunning | back to summary |
|---|---|
| public boolean isRunning() Implements org. Doc from org. Check whether this component is currently running. In the case of a container, this will return
| |
| isValidOrigin | back to summary |
|---|---|
| protected boolean isValidOrigin(ServerHttpRequest request) Return whether the request | |
| isWebSocketVersionSupported | back to summary |
|---|---|
| protected boolean isWebSocketVersionSupported(WebSocketHttpHeaders httpHeaders) | |
| selectProtocol | back to summary |
|---|---|
| protected String selectProtocol(List<String> requestedProtocols, WebSocketHandler webSocketHandler) Perform the sub-protocol negotiation based on requested and supported sub-protocols.
For the list of supported sub-protocols, this method first checks if the target
WebSocketHandler is a
| |
| setSupportedProtocols | back to summary |
|---|---|
| public void setSupportedProtocols(String... protocols) Use this property to configure the list of supported sub-protocols. The first configured sub-protocol that matches a client-requested sub-protocol is accepted. If there are no matches the response will not contain a Sec-WebSocket-Protocol header. Note that if the WebSocketHandler passed in at runtime is an instance of
| |
| start | back to summary |
|---|---|
| public void start() Implements org. Doc from org. Start this component. Should 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.
| |
| stop | back to summary |
|---|---|
| public void stop() Implements org. Doc from org. Stop this component, typically in a synchronous fashion, such that the component is
fully stopped upon return of this method. Consider implementing Note that this stop notification is not guaranteed to come before destruction:
On regular shutdown, Should not throw an exception if the component is not running (not started yet). In the case of a container, this will propagate the stop signal to all components that apply.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static RequestUpgradeStrategy | |
| public static RequestUpgradeStrategy |
| TyrusStrategyDelegate | back to summary |
|---|---|
| private TyrusStrategyDelegate() | |
| forGlassFish | back to summary |
|---|---|
| public static RequestUpgradeStrategy forGlassFish() | |
| forWebLogic | back to summary |
|---|---|
| public static RequestUpgradeStrategy forWebLogic() | |