Class HandshakeWebSocketService

  • java.lang.Object
  • All Implemented Interfaces:
    Lifecycle, WebSocketService

    public class HandshakeWebSocketService
    extends java.lang.Object
    implements WebSocketService, Lifecycle
    WebSocketService implementation that handles a WebSocket HTTP handshake request by delegating to a RequestUpgradeStrategy which is either auto-detected (no-arg constructor) from the classpath but can also be explicitly configured.
    Rossen Stoyanchev
    • Field Detail

      • logger

        protected static final Log logger
    • Constructor Detail

      • HandshakeWebSocketService

        public HandshakeWebSocketService()
        Default constructor automatic, classpath detection based discovery of the RequestUpgradeStrategy to use.
    • Method Detail

      • setSessionAttributePredicate

        public void setSessionAttributePredicate(@Nullable
                                                 java.util.function.Predicate<java.lang.String> predicate)
        Configure a predicate to use to extract WebSession attributes and use them to initialize the WebSocket session with.

        By default this is not set in which case no attributes are passed.

        predicate - the predicate
      • getSessionAttributePredicate

        public java.util.function.Predicate<java.lang.String> getSessionAttributePredicate()
        Return the configured predicate for initialization WebSocket session attributes from WebSession attributes.
      • 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:
      • doStart

        protected void doStart()
      • 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:
        SmartLifecycle.stop(Runnable), DisposableBean.destroy()
      • doStop

        protected void doStop()
      • 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
      • handleRequest

        public reactor.core.publisher.Mono<java.lang.Void> handleRequest(ServerWebExchange exchange,
                                                                         WebSocketHandler handler)
        Description copied from interface: WebSocketService
        Handle the request with the given WebSocketHandler.
        Specified by:
        handleRequest in interface WebSocketService
        exchange - the current exchange
        handler - handler for WebSocket session
        a Mono<Void> that completes when application handling of the WebSocket session completes.