|
1 | 1 | /* |
2 | | - * Copyright 2014-2022 the original author or authors. |
| 2 | + * Copyright 2014-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.integration.websocket; |
18 | 18 |
|
| 19 | +import java.net.URI; |
19 | 20 | import java.util.Map; |
20 | 21 | import java.util.concurrent.CompletableFuture; |
21 | 22 | import java.util.concurrent.CountDownLatch; |
@@ -56,21 +57,32 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine |
56 | 57 |
|
57 | 58 | private final IntegrationWebSocketConnectionManager connectionManager; |
58 | 59 |
|
| 60 | + private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; |
| 61 | + |
59 | 62 | private volatile CountDownLatch connectionLatch; |
60 | 63 |
|
61 | 64 | private volatile WebSocketSession clientSession; |
62 | 65 |
|
63 | 66 | private volatile Throwable openConnectionException; |
64 | 67 |
|
65 | | - private volatile int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; |
66 | | - |
67 | 68 | private volatile boolean connecting; |
68 | 69 |
|
69 | 70 | public ClientWebSocketContainer(WebSocketClient client, String uriTemplate, Object... uriVariables) { |
70 | 71 | Assert.notNull(client, "'client' must not be null"); |
71 | 72 | this.connectionManager = new IntegrationWebSocketConnectionManager(client, uriTemplate, uriVariables); |
72 | 73 | } |
73 | 74 |
|
| 75 | + /** |
| 76 | + * Constructor with a prepared {@link URI}. |
| 77 | + * @param client the {@link WebSocketClient} to use. |
| 78 | + * @param uri the url to connect to |
| 79 | + * @since 6.1 |
| 80 | + */ |
| 81 | + public ClientWebSocketContainer(WebSocketClient client, URI uri) { |
| 82 | + Assert.notNull(client, "'client' must not be null"); |
| 83 | + this.connectionManager = new IntegrationWebSocketConnectionManager(client, uri); |
| 84 | + } |
| 85 | + |
74 | 86 | public void setOrigin(String origin) { |
75 | 87 | this.headers.setOrigin(origin); |
76 | 88 | } |
@@ -204,13 +216,18 @@ private final class IntegrationWebSocketConnectionManager extends ConnectionMana |
204 | 216 |
|
205 | 217 | private final boolean syncClientLifecycle; |
206 | 218 |
|
207 | | - IntegrationWebSocketConnectionManager(WebSocketClient client, String uriTemplate, |
208 | | - Object... uriVariables) { |
| 219 | + IntegrationWebSocketConnectionManager(WebSocketClient client, String uriTemplate, Object... uriVariables) { |
209 | 220 | super(uriTemplate, uriVariables); |
210 | 221 | this.client = client; |
211 | 222 | this.syncClientLifecycle = ((client instanceof Lifecycle) && !((Lifecycle) client).isRunning()); |
212 | 223 | } |
213 | 224 |
|
| 225 | + IntegrationWebSocketConnectionManager(WebSocketClient client, URI uri) { |
| 226 | + super(uri); |
| 227 | + this.client = client; |
| 228 | + this.syncClientLifecycle = ((client instanceof Lifecycle) && !((Lifecycle) client).isRunning()); |
| 229 | + } |
| 230 | + |
214 | 231 | @Override |
215 | 232 | public void startInternal() { |
216 | 233 | if (this.syncClientLifecycle) { |
|
0 commit comments