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

public Class SockJsHttpRequestHandler

extends Object
implements HttpRequestHandler, CorsConfigurationSource, Lifecycle, ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware, org.springframework.context.Lifecycle, org.springframework.web.cors.CorsConfigurationSource, org.springframework.web.HttpRequestHandler
Imports
java.io.IOException, jakarta.servlet.ServletContext, .ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, 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.cors.CorsConfiguration, .CorsConfigurationSource, org.springframework.web.servlet.HandlerMapping, org.springframework.web.socket.WebSocketHandler, org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator, .LoggingWebSocketHandlerDecorator, org.springframework.web.socket.sockjs.SockJsException, .SockJsService

An HttpRequestHandler that allows mapping a SockJsService to requests in a Servlet container.
Authors
Rossen Stoyanchev, Sebastien Deleuze
Since
4.0

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final SockJsService
private final WebSocketHandler

Constructor Summary

AccessConstructor and Description
public
SockJsHttpRequestHandler(SockJsService
the SockJS service
sockJsService
,
WebSocketHandler
the websocket handler
webSocketHandler
)

Create a new SockJsHttpRequestHandler.

Method Summary

Modifier and TypeMethod and Description
public CorsConfiguration
private String
public SockJsService
public 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
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

runningback to summary
private volatile boolean running
sockJsServiceback to summary
private final SockJsService sockJsService
webSocketHandlerback to summary
private final WebSocketHandler webSocketHandler

Constructor Detail

SockJsHttpRequestHandlerback to summary
public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler)

Create a new SockJsHttpRequestHandler.

Parameters
sockJsService:SockJsService

the SockJS service

webSocketHandler:WebSocketHandler

the websocket handler

Method Detail

getCorsConfigurationback to summary
public CorsConfiguration getCorsConfiguration(HttpServletRequest request)

Implements org.springframework.web.cors.CorsConfigurationSource.getCorsConfiguration.

Doc from org.springframework.web.cors.CorsConfigurationSource.getCorsConfiguration.

Return a CorsConfiguration based on the incoming request.

Returns:CorsConfiguration

the associated CorsConfiguration, or null if none

Annotations
@Override
@Nullable
getSockJsPathback to summary
private String getSockJsPath(HttpServletRequest servletRequest)
getSockJsServiceback to summary
public SockJsService getSockJsService()

Return the SockJsService.

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
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