org.springframework.web.socket.client

## Class WebSocketConnectionManager

- java.lang.Object
- - org.springframework.web.socket.client.ConnectionManagerSupport
  - - org.springframework.web.socket.client.WebSocketConnectionManager

- All Implemented Interfaces:
    Lifecycle, Phased, SmartLifecycle

      public class WebSocketConnectionManager
      extends ConnectionManagerSupport

  A WebSocket connection manager that is given a URI, a `WebSocketClient`, and a `WebSocketHandler`, connects to a WebSocket server through `ConnectionManagerSupport.start()` and `ConnectionManagerSupport.stop()` methods. If `ConnectionManagerSupport.setAutoStartup(boolean)` is set to `true` this will be done automatically when the Spring ApplicationContext is refreshed.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

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

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `closeConnection()`
    `protected WebSocketHandler` | `decorateWebSocketHandler(WebSocketHandler handler)` Decorate the WebSocketHandler provided to the class constructor.
    `HttpHeaders` | `getHeaders()` Return the default headers for the WebSocket handshake request.
    `String` | `getOrigin()`
    `List<String>` | `getSubProtocols()` Return the configured sub-protocols to use.
    `protected boolean` | `isConnected()`
    `protected void` | `openConnection()`
    `void` | `setHeaders(HttpHeaders headers)` Provide default headers to add to the WebSocket handshake request.
    `void` | `setOrigin(String origin)` Set the origin to use.
    `void` | `setSubProtocols(List<String> protocols)` Set the sub-protocols to use.
    `void` | `startInternal()`
    `void` | `stopInternal()`

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

      `getPhase, getUri, isAutoStartup, isRunning, setAutoStartup, setPhase, start, stop, stop`

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

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

- - ### Constructor Detail

    - #### WebSocketConnectionManager

          public WebSocketConnectionManager(WebSocketClient client,
                                            WebSocketHandler webSocketHandler,
                                            String uriTemplate,
                                            Object... uriVariables)

  - ### Method Detail

    - #### decorateWebSocketHandler

          protected WebSocketHandler decorateWebSocketHandler(WebSocketHandler handler)

      Decorate the WebSocketHandler provided to the class constructor.

      By default `LoggingWebSocketHandlerDecorator` is added.

    - #### setSubProtocols

          public void setSubProtocols(List<String> protocols)

      Set the sub-protocols to use. If configured, specified sub-protocols will be requested in the handshake through the `Sec-WebSocket-Protocol` header. The resulting WebSocket session will contain the protocol accepted by the server, if any.

    - #### getSubProtocols

          public List<String> getSubProtocols()

      Return the configured sub-protocols to use.

    - #### setOrigin

          public void setOrigin(String origin)

      Set the origin to use.

    - #### getOrigin

          public String getOrigin()

      Returns:
        the configured origin.

    - #### setHeaders

          public void setHeaders(HttpHeaders headers)

      Provide default headers to add to the WebSocket handshake request.

    - #### getHeaders

          public HttpHeaders getHeaders()

      Return the default headers for the WebSocket handshake request.

    - #### startInternal

          public void startInternal()

      Overrides:
        `startInternal` in class `ConnectionManagerSupport`

    - #### stopInternal

          public void stopInternal()
                            throws Exception

      Overrides:
        `stopInternal` in class `ConnectionManagerSupport`
      Throws:
        `Exception`

    - #### openConnection

          protected void openConnection()

      Specified by:
        `openConnection` in class `ConnectionManagerSupport`

    - #### closeConnection

          protected void closeConnection()
                                  throws Exception

      Specified by:
        `closeConnection` in class `ConnectionManagerSupport`
      Throws:
        `Exception`

    - #### isConnected

          protected boolean isConnected()

      Specified by:
        `isConnected` in class `ConnectionManagerSupport`