spring-framework / org.springframework.web.socket.server.support / AbstractHandshakeHandler

AbstractHandshakeHandler

abstract class AbstractHandshakeHandler : HandshakeHandler, Lifecycle

A base class for HandshakeHandler implementations, independent from 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.springframework.web.socket.server.RequestUpgradeStrategy, which will update the response as necessary and initialize the WebSocket. Currently supported servers are Jetty 9.0-9.3, Tomcat 7.0.47+ and 8.x, Undertow 1.0-1.3, GlassFish 4.1+, WebLogic 12.1.3+.

Author
Rossen Stoyanchev

Author
Juergen Hoeller

Since
4.2

See Also
org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategyorg.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategyorg.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategyorg.springframework.web.socket.server.standard.GlassFishRequestUpgradeStrategyorg.springframework.web.socket.server.standard.WebLogicRequestUpgradeStrategy

Functions

doHandshake

fun doHandshake(request: ServerHttpRequest, response: ServerHttpResponse, wsHandler: WebSocketHandler, attributes: MutableMap<String, Any>): Boolean

getRequestUpgradeStrategy

open fun getRequestUpgradeStrategy(): RequestUpgradeStrategy

Return the RequestUpgradeStrategy for WebSocket requests.

getSupportedProtocols

open fun getSupportedProtocols(): Array<String>

Return the list of supported sub-protocols.

isRunning

open fun isRunning(): Boolean

setSupportedProtocols

open fun setSupportedProtocols(vararg protocols: String): Unit

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 SubProtocolCapable then there is not need to explicitly configure this property. That is certainly the case with the built-in STOMP over WebSocket support. Therefore this property should be configured explicitly only if the WebSocketHandler does not implement SubProtocolCapable.

start

open fun start(): Unit

stop

open fun stop(): Unit