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

public Class WebSocketHandlerMapping

extends SimpleUrlHandlerMapping
implements SmartLifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.SmartLifecycle, org.springframework.context.Phased, org.springframework.context.Lifecycle
Imports
jakarta.servlet.ServletContext, jakarta.servlet.http.HttpServletRequest, org.springframework.context.Lifecycle, .SmartLifecycle, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.HandlerExecutionChain, org.springframework.web.servlet.handler.SimpleUrlHandlerMapping

Extension of SimpleUrlHandlerMapping with support for more precise mapping of WebSocket handshake requests to handlers of type WebSocketHttpRequestHandler. Also delegates Lifecycle methods to handlers in the getUrlMap() that implement it.
Author
Rossen Stoyanchev
Since
4.2

Field Summary

Modifier and TypeField and Description
private Integer
private volatile boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Object
getHandlerInternal(HttpServletRequest
current HTTP request
request
)

Overrides org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal.

Look up a handler for the URL path of the given request.

public int
getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase that this lifecycle object is supposed to run in.

The default implementation returns DEFAULT_PHASE in order to let stop() callbacks execute before regular Lifecycle implementations.

protected void
initServletContext(ServletContext
the ServletContext that this application object runs in (never null)
servletContext
)

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

private boolean
public void
setPhase(int phase)

Set the phase that this handler should run in.

By default, this is SmartLifecycle#DEFAULT_PHASE.

public void
setWebSocketUpgradeMatch(boolean
whether to enable matching on "Upgrade: websocket"
match
)

When this is set, if the matched handler is WebSocketHttpRequestHandler, ensure the request is a WebSocket handshake, i.e. HTTP GET with the header "Upgrade:websocket", or otherwise suppress the match and return null allowing another org.springframework.web.servlet.HandlerMapping to match for the same URL path.

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 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping:
getUrlMapinitApplicationContextregisterHandlerssetMappingssetUrlMap

Field Detail

phaseback to summary
private Integer phase
Annotations
@Nullable
runningback to summary
private volatile boolean running
webSocketUpgradeMatchback to summary
private boolean webSocketUpgradeMatch

Constructor Detail

WebSocketHandlerMappingback to summary
public WebSocketHandlerMapping()

Method Detail

getHandlerInternalback to summary
protected Object getHandlerInternal(HttpServletRequest request) throws Exception

Overrides org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal.

Doc from org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal.

Look up a handler for the URL path of the given request.

Parameters
request:HttpServletRequest

current HTTP request

Returns:Object

the handler instance, or null if none found

Annotations
@Override
@Nullable
Exceptions
Exception:

Doc from org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerInternal.

if there is an internal error

getPhaseback to summary
public int getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Doc from org.springframework.context.SmartLifecycle.getPhase.

Return the phase that this lifecycle object is supposed to run in.

The default implementation returns DEFAULT_PHASE in order to let stop() callbacks execute before regular Lifecycle implementations.

Annotations
@Override
initServletContextback to summary
protected void initServletContext(ServletContext servletContext)

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Doc from org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty. Called by initApplicationContext(org.springframework.context.ApplicationContext) as well as setServletContext(jakarta.servlet.ServletContext).

Parameters
servletContext:ServletContext

the ServletContext that this application object runs in (never null)

Annotations
@Override
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
matchWebSocketUpgradeback to summary
private boolean matchWebSocketUpgrade(Object handler, HttpServletRequest request)
setPhaseback to summary
public void setPhase(int phase)

Set the phase that this handler should run in.

By default, this is SmartLifecycle#DEFAULT_PHASE.

Since
6.1.4
setWebSocketUpgradeMatchback to summary
public void setWebSocketUpgradeMatch(boolean match)

When this is set, if the matched handler is WebSocketHttpRequestHandler, ensure the request is a WebSocket handshake, i.e. HTTP GET with the header "Upgrade:websocket", or otherwise suppress the match and return null allowing another org.springframework.web.servlet.HandlerMapping to match for the same URL path.

Parameters
match:boolean

whether to enable matching on "Upgrade: websocket"

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