org.springframework.web.socket.client.standard

## Class StandardWebSocketClient

- java.lang.Object
- - org.springframework.web.socket.client.AbstractWebSocketClient
  - - org.springframework.web.socket.client.standard.StandardWebSocketClient

- All Implemented Interfaces:
    WebSocketClient

      public class StandardWebSocketClient
      extends AbstractWebSocketClient

  Initiates WebSocket requests to a WebSocket server programmatically through the standard Java 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
    `StandardWebSocketClient()` Default constructor that calls `ContainerProvider.getWebSocketContainer()` to obtain a (new) `WebSocketContainer` instance.
    `StandardWebSocketClient(javax.websocket.WebSocketContainer webSocketContainer)` Constructor accepting an existing `WebSocketContainer` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected ListenableFuture<WebSocketSession>` | `doHandshakeInternal(WebSocketHandler webSocketHandler, 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.
    `AsyncListenableTaskExecutor` | `getTaskExecutor()` Return the configured `TaskExecutor`.
    `void` | `setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)` Set an `AsyncListenableTaskExecutor` to use when opening connections.

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

      `doHandshake, doHandshake`

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

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

- - ### Constructor Detail

    - #### StandardWebSocketClient

          public StandardWebSocketClient()

      Default constructor that calls `ContainerProvider.getWebSocketContainer()` to obtain a (new) `WebSocketContainer` instance. Also see constructor accepting existing `WebSocketContainer` instance.

    - #### StandardWebSocketClient

          public StandardWebSocketClient(javax.websocket.WebSocketContainer webSocketContainer)

      Constructor accepting an existing `WebSocketContainer` instance.

      For XML configuration see `WebSocketContainerFactoryBean`. For Java configuration use `ContainerProvider.getWebSocketContainer()` to obtain the `WebSocketContainer` 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`.

    - #### doHandshakeInternal

          protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
                                                                           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:
        `webSocketHandler` - 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.