org.springframework.web.socket.client.jetty

## Class JettyWebSocketClient

- java.lang.Object
- - org.springframework.web.socket.client.AbstractWebSocketClient
  - - org.springframework.web.socket.client.jetty.JettyWebSocketClient

- All Implemented Interfaces:
    Lifecycle, Phased, SmartLifecycle, WebSocketClient

      public class JettyWebSocketClient
      extends AbstractWebSocketClient
      implements SmartLifecycle

  Initiates WebSocket requests to a WebSocket server programmatically through the Jetty WebSocket API.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.socket.client.AbstractWebSocketClient

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JettyWebSocketClient()` Default constructor that creates an instance of `WebSocketClient`.
    `JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)` Constructor that accepts an existing `WebSocketClient` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ListenableFuture<WebSocketSession>` | `doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVars)`
    `ListenableFuture<WebSocketSession>` | `doHandshakeInternal(WebSocketHandler wsHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String,Object> attributes)` Perform the actual handshake to establish a connection to the server.
    `int` | `getPhase()` Return the phase value of this object.
    `AsyncListenableTaskExecutor` | `getTaskExecutor()` Return the configured `TaskExecutor`.
    `protected Principal` | `getUser()`
    `boolean` | `isAutoStartup()` Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed.
    `boolean` | `isRunning()` Check whether this component is currently running.
    `void` | `setAutoStartup(boolean autoStartup)`
    `void` | `setPhase(int phase)`
    `void` | `setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)` Set an `AsyncListenableTaskExecutor` to use when opening connections.
    `void` | `start()` Start this component.
    `void` | `stop()` Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
    `void` | `stop(Runnable callback)` Indicates that a Lifecycle component must stop if it is currently running.

    - ### Methods inherited from class org.springframework.web.socket.client.AbstractWebSocketClient

      `doHandshake`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JettyWebSocketClient

          public JettyWebSocketClient()

      Default constructor that creates an instance of `WebSocketClient`.

    - #### JettyWebSocketClient

          public JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client)

      Constructor that accepts an existing `WebSocketClient` instance.

  - ### Method Detail

    - #### setTaskExecutor

          public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)

      Set an `AsyncListenableTaskExecutor` to use when opening connections.

      If this property is not configured, calls to any of the `doHandshake` methods will block until the connection is established.

    - #### getTaskExecutor

          public AsyncListenableTaskExecutor getTaskExecutor()

      Return the configured `TaskExecutor`.

    - #### setAutoStartup

          public void setAutoStartup(boolean autoStartup)

    - #### isAutoStartup

          public boolean isAutoStartup()

      Description copied from interface: `SmartLifecycle`
      Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed. A value of "false" indicates that the component is intended to be started manually.
      Specified by:
        `isAutoStartup` in interface `SmartLifecycle`

    - #### setPhase

          public void setPhase(int phase)

    - #### getPhase

          public int getPhase()

      Description copied from interface: `Phased`
      Return the phase value of this object.
      Specified by:
        `getPhase` in interface `Phased`

    - #### 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`
      Returns:
        whether the component is currently running

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

    - #### 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 in cases where asynchronous stop behavior is necessary.

      Should not throw an exception if the component isn't 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)`

    - #### stop

          public void stop(Runnable callback)

      Description copied from interface: `SmartLifecycle`
      Indicates that a Lifecycle component must stop if it is currently running.

      The provided callback is used by the `LifecycleProcessor` to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.

      The `LifecycleProcessor` will call only this variant of the `stop` method; i.e. `Lifecycle.stop()` will not be called for `SmartLifecycle` implementations unless explicitly delegated to within this method.

      Specified by:
        `stop` in interface `SmartLifecycle`

    - #### doHandshake

          public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
                                                                String uriTemplate,
                                                                Object... uriVars)

      Specified by:
        `doHandshake` in interface `WebSocketClient`
      Overrides:
        `doHandshake` in class `AbstractWebSocketClient`

    - #### doHandshakeInternal

          public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
                                                                        HttpHeaders headers,
                                                                        URI uri,
                                                                        List<String> protocols,
                                                                        List<WebSocketExtension> extensions,
                                                                        Map<String,Object> attributes)

      Description copied from class: `AbstractWebSocketClient`
      Perform the actual handshake to establish a connection to the server.
      Specified by:
        `doHandshakeInternal` in class `AbstractWebSocketClient`
      Parameters:
        `wsHandler` - the client-side handler for WebSocket messages
        `headers` - HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out, never `null`
        `uri` - the target URI for the handshake, never `null`
        `protocols` - requested sub-protocols, or an empty list
        `extensions` - requested WebSocket extensions, or an empty list
        `attributes` - attributes to associate with the WebSocketSession, i.e. via `WebSocketSession.getAttributes()`; currently always an empty map.
      Returns:
        the established WebSocket session wrapped in a ListenableFuture.

    - #### getUser

          protected Principal getUser()

      Returns:
        the user to make available through `WebSocketSession.getPrincipal()`; by default this method returns `null`