title: What is the proper way to use Spring WebSocketConnectionManager when sessions closes
body: <p>I use Spring's <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/socket/client/WebSocketConnectionManager.html" rel="nofollow noreferrer">WebSocketConnectionManager</a> to work with WebSockets. Sometimes the connection closes and I have to reconnect. But I didn't find any proper solution to do that. Can I use WebSocketConnectionManager for restore (reconnect to) session? In the <a href="https://github.com/spring-projects/spring-framework/blob/a89e716cc71a8741385a0224b5d7eb7ce009e11a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java" rel="nofollow noreferrer">sources I see</a>, that connection establishes by the following code:</p>
  
  <pre><code>@Override
  protected void openConnection() {
      if (logger.isInfoEnabled()) {
          logger.info("Connecting to WebSocket at " + getUri());
      }
  
      ListenableFuture&lt;WebSocketSession&gt; future =
              this.client.doHandshake(this.webSocketHandler, this.headers, getUri());
  
      future.addCallback(new ListenableFutureCallback&lt;WebSocketSession&gt;() {
          @Override
          public void onSuccess(@Nullable WebSocketSession result) {
              webSocketSession = result;
              logger.info("Successfully connected");
          }
          @Override
          public void onFailure(Throwable ex) {
              logger.error("Failed to connect", ex);
          }
      });
  }
  </code></pre>
  
  <p>And I'm using this Manager when my spring boot application start by:</p>
  
  <pre><code>WebSocketConnectionManager connectionManager = new WebSocketConnectionManager(
      new StandardWebSocketClient(), webSocketHandler, "wss://localhost:8080/ws/");
  
  connectionManager.start();
  </code></pre>
  
  <p>But what I have to do when connection closes? I tried to copy a piece of code from openConnection(), and use it for update the session directly in webSocketHandler, and it works. But it looks like dirty workaround.</p>
  
  <p>Does anybody know how to do it correctly? Thank you.</p>