Class WebSocketHandlerMapping
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ApplicationContextAware,- Lifecycle,- Phased,- SmartLifecycle,- Ordered,- ServletContextAware,- MatchableHandlerMapping,- HandlerMapping
SimpleUrlHandlerMapping with support for more
 precise mapping of WebSocket handshake requests to handlers of type
 WebSocketHttpRequestHandler. Also delegates Lifecycle
 methods to handlers in the SimpleUrlHandlerMapping.getUrlMap() that implement it.- Since:
- 4.2
- Author:
- Rossen Stoyanchev
- 
Field SummaryFields inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingmappingsLoggerFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.HandlerMappingBEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected ObjectgetHandlerInternal(HttpServletRequest request) Look up a handler for the URL path of the given request.intgetPhase()Return the phase that this lifecycle object is supposed to run in.protected voidinitServletContext(ServletContext servletContext) Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.booleanCheck whether this component is currently running.voidsetPhase(int phase) Set the phase that this handler should run in.voidsetWebSocketUpgradeMatch(boolean match) When this is set, if the matched handler isWebSocketHttpRequestHandler, ensure the request is a WebSocket handshake, i.e.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.Methods inherited from class org.springframework.web.servlet.handler.SimpleUrlHandlerMappinggetUrlMap, initApplicationContext, registerHandlers, setMappings, setUrlMapMethods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMappingbuildPathExposingHandler, exposePathWithinMapping, exposeUriTemplateVariables, getHandlerMap, getPathPatternHandlerMap, getRootHandler, lookupHandler, lookupHandler, match, registerHandler, registerHandler, setLazyInitHandlers, setPatternParser, setRootHandler, setUseTrailingSlashMatch, supportsTypeLevelMappings, unregisterHandler, useTrailingSlashMatch, validateHandlerMethods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingadaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfiguration, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, hasCorsConfigurationSource, initInterceptors, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatternsMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContextMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.servlet.HandlerMappinggetHandler, usesPathPatternsMethods inherited from interface org.springframework.web.servlet.handler.MatchableHandlerMappinggetPatternParserMethods inherited from interface org.springframework.context.SmartLifecycleisAutoStartup, stop
- 
Constructor Details- 
WebSocketHandlerMappingpublic WebSocketHandlerMapping()
 
- 
- 
Method Details- 
setWebSocketUpgradeMatchpublic void setWebSocketUpgradeMatch(boolean match) When this is set, if the matched handler isWebSocketHttpRequestHandler, ensure the request is a WebSocket handshake, i.e. HTTP GET with the header"Upgrade:websocket", or otherwise suppress the match and returnnullallowing anotherHandlerMappingto match for the same URL path.- Parameters:
- match- whether to enable matching on- "Upgrade: websocket"
- Since:
- 5.3.5
 
- 
setPhasepublic void setPhase(int phase) Set the phase that this handler should run in.By default, this is SmartLifecycle.DEFAULT_PHASE, but with@EnableWebSocketMessageBrokerconfiguration it is set to 0.- Since:
- 6.1.4
 
- 
getPhasepublic int getPhase()Description copied from interface:SmartLifecycleReturn the phase that this lifecycle object is supposed to run in.The default implementation returns SmartLifecycle.DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.- Specified by:
- getPhasein interface- Phased
- Specified by:
- getPhasein interface- SmartLifecycle
- See Also:
 
- 
initServletContextDescription copied from class:WebApplicationObjectSupportSubclasses may override this for custom initialization based on the ServletContext that this application object runs in.The default implementation is empty. Called by WebApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)as well asWebApplicationObjectSupport.setServletContext(jakarta.servlet.ServletContext).- Overrides:
- initServletContextin class- WebApplicationObjectSupport
- Parameters:
- servletContext- the ServletContext that this application object runs in (never- null)
 
- 
startpublic void start()Description copied from interface:LifecycleStart this component.Should not throw an exception if the component is already running. In the case of a container, this will propagate a hard start signal to all components that apply, even to non-auto-startup components. 
- 
stoppublic void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecyclebeans 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. 
- 
isRunningpublic boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return trueonly if all components that apply are currently running.
- 
getHandlerInternalDescription copied from class:AbstractUrlHandlerMappingLook up a handler for the URL path of the given request.- Overrides:
- getHandlerInternalin class- AbstractUrlHandlerMapping
- Parameters:
- request- current HTTP request
- Returns:
- the handler instance, or nullif none found
- Throws:
- Exception- if there is an internal error
 
 
-