Skip to content

Commit 9fcafd2

Browse files
committed
WebSocketConnectionManager accepts prepared URI
Closes gh-28524
1 parent ccbb4bd commit 9fcafd2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,9 +49,20 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle {
4949
private final Object lifecycleMonitor = new Object();
5050

5151

52+
/**
53+
* Constructor with a URI template and variables.
54+
*/
5255
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) {
53-
this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(
54-
uriVariables).encode().toUri();
56+
this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri();
57+
}
58+
59+
/**
60+
* Constructor with a prepared {@link URI}.
61+
* @param uri the url to connect to
62+
* @since 6.0.5
63+
*/
64+
public ConnectionManagerSupport(URI uri) {
65+
this.uri = uri;
5566
}
5667

5768

spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.socket.client;
1818

19+
import java.net.URI;
1920
import java.util.List;
2021
import java.util.concurrent.CompletableFuture;
2122

@@ -48,6 +49,9 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
4849
private final WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
4950

5051

52+
/**
53+
* Constructor with the client to use and a handler to handle messages with.
54+
*/
5155
public WebSocketConnectionManager(WebSocketClient client,
5256
WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) {
5357

@@ -56,6 +60,17 @@ public WebSocketConnectionManager(WebSocketClient client,
5660
this.webSocketHandler = decorateWebSocketHandler(webSocketHandler);
5761
}
5862

63+
/**
64+
* Variant of {@link #WebSocketConnectionManager(WebSocketClient, WebSocketHandler, String, Object...)}
65+
* with a prepared {@link URI}.
66+
* @since 6.0.5
67+
*/
68+
public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, URI uri) {
69+
super(uri);
70+
this.client = client;
71+
this.webSocketHandler = decorateWebSocketHandler(webSocketHandler);
72+
}
73+
5974

6075
/**
6176
* Set the sub-protocols to use. If configured, specified sub-protocols will be

0 commit comments

Comments
 (0)