Top Description Fields Constructors Methods
org.springframework.web.socket.server.support

public Class WebSocketHttpRequestHandler

extends Object
implements HttpRequestHandler, Lifecycle, ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware, org.springframework.context.Lifecycle, org.springframework.web.HttpRequestHandler
Imports
java.io.IOException, java.util.ArrayList, .HashMap, .List, .Map, jakarta.servlet.ServletContext, .ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.commons.logging.Log, .LogFactory, org.springframework.context.Lifecycle, org.springframework.http.server.ServerHttpRequest, .ServerHttpResponse, .ServletServerHttpRequest, .ServletServerHttpResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.HttpRequestHandler, org.springframework.web.context.ServletContextAware, org.springframework.web.socket.WebSocketHandler, org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator, .LoggingWebSocketHandlerDecorator, org.springframework.web.socket.server.HandshakeFailureException, .HandshakeHandler, .HandshakeInterceptor

A HttpRequestHandler for processing WebSocket handshake requests.

This is the main class to use when configuring a server WebSocket at a specific URL. It is a very thin wrapper around a WebSocketHandler and a HandshakeHandler, also adapting the HttpServletRequest and HttpServletResponse to ServerHttpRequest and ServerHttpResponse, respectively.

Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private final HandshakeHandler
private final List<HandshakeInterceptor>
private static final Log
private volatile boolean
private final WebSocketHandler

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected WebSocketHandler
decorate(WebSocketHandler handler)

Decorate the WebSocketHandler passed into the constructor.

public HandshakeHandler
getHandshakeHandler()

Return the HandshakeHandler.

public List<HandshakeInterceptor>
getHandshakeInterceptors()

Return the configured WebSocket handshake request interceptors.

public WebSocketHandler
getWebSocketHandler()

Return the WebSocketHandler.

public void
handleRequest(HttpServletRequest
current HTTP request
servletRequest
,
HttpServletResponse
current HTTP response
servletResponse
)

Implements org.springframework.web.HttpRequestHandler.handleRequest.

Process the given request, generating a response.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

public void
setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)

Configure one or more WebSocket handshake request interceptors.

public void
setServletContext(ServletContext
the ServletContext object to be used by this object
servletContext
)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handshakeHandlerback to summary
private final HandshakeHandler handshakeHandler
interceptorsback to summary
private final List<HandshakeInterceptor> interceptors
loggerback to summary
private static final Log logger
runningback to summary
private volatile boolean running
wsHandlerback to summary
private final WebSocketHandler wsHandler

Constructor Detail

WebSocketHttpRequestHandlerback to summary
public WebSocketHttpRequestHandler(WebSocketHandler wsHandler)
WebSocketHttpRequestHandlerback to summary
public WebSocketHttpRequestHandler(WebSocketHandler wsHandler, HandshakeHandler handshakeHandler)

Method Detail

decorateback to summary
protected WebSocketHandler decorate(WebSocketHandler handler)

Decorate the WebSocketHandler passed into the constructor.

By default, LoggingWebSocketHandlerDecorator and ExceptionWebSocketHandlerDecorator are added.

Since
5.2.2
getHandshakeHandlerback to summary
public HandshakeHandler getHandshakeHandler()

Return the HandshakeHandler.

getHandshakeInterceptorsback to summary
public List<HandshakeInterceptor> getHandshakeInterceptors()

Return the configured WebSocket handshake request interceptors.

getWebSocketHandlerback to summary
public WebSocketHandler getWebSocketHandler()

Return the WebSocketHandler.

handleRequestback to summary
public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException

Implements org.springframework.web.HttpRequestHandler.handleRequest.

Doc from org.springframework.web.HttpRequestHandler.handleRequest.

Process the given request, generating a response.

Parameters
servletRequest:HttpServletRequest

current HTTP request

servletResponse:HttpServletResponse

current HTTP response

Annotations
@Override
Exceptions
ServletException:
in case of general errors
IOException:
in case of I/O errors
isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

In the case of a container, this will return true only if all components that apply are currently running.

Returns:boolean

whether the component is currently running

Annotations
@Override
setHandshakeInterceptorsback to summary
public void setHandshakeInterceptors(List<HandshakeInterceptor> interceptors)

Configure one or more WebSocket handshake request interceptors.

setServletContextback to summary
public void setServletContext(ServletContext servletContext)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

Doc from org.springframework.web.context.ServletContextAware.setServletContext.

Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Parameters
servletContext:ServletContext

the ServletContext object to be used by this object

Annotations
@Override
startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

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.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

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.

Annotations
@Override