Class WebSocketHandlerMapping

All Implemented Interfaces:
Aware, BeanNameAware, ApplicationContextAware, Lifecycle, Phased, SmartLifecycle, Ordered, ServletContextAware, MatchableHandlerMapping, HandlerMapping

public class WebSocketHandlerMapping extends SimpleUrlHandlerMapping implements SmartLifecycle
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 SimpleUrlHandlerMapping.getUrlMap() that implement it.
Rossen Stoyanchev
  • Constructor Details

    • WebSocketHandlerMapping

      public WebSocketHandlerMapping()
  • Method Details

    • setWebSocketUpgradeMatch

      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 HandlerMapping to match for the same URL path.
      match - whether to enable matching on "Upgrade: websocket"
    • initServletContext

      protected void initServletContext(ServletContext servletContext)
      Description copied from class: WebApplicationObjectSupport
      Subclasses 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 as WebApplicationObjectSupport.setServletContext(jakarta.servlet.ServletContext).

      initServletContext in class WebApplicationObjectSupport
      servletContext - the ServletContext that this application object runs in (never null)
    • start

      public void start()
      Description copied from interface: Lifecycle
      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.

      Specified by:
      start in interface Lifecycle
      See Also:
    • stop

      public void stop()
      Description copied from interface: Lifecycle
      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.

      Specified by:
      stop in interface Lifecycle
      See Also:
    • isRunning

      public boolean isRunning()
      Description copied from interface: Lifecycle
      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.

      Specified by:
      isRunning in interface Lifecycle
      whether the component is currently running
    • getHandlerInternal

      @Nullable protected Object getHandlerInternal(HttpServletRequest request) throws Exception
      Description copied from class: AbstractUrlHandlerMapping
      Look up a handler for the URL path of the given request.
      getHandlerInternal in class AbstractUrlHandlerMapping
      request - current HTTP request
      the handler instance, or null if none found
      Exception - if there is an internal error