From 9fcafd265037f6d7015f1cdbfa4936a23c202c91 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 13 Feb 2023 17:10:19 +0000 Subject: [PATCH] WebSocketConnectionManager accepts prepared URI Closes gh-28524 --- .../socket/client/ConnectionManagerSupport.java | 17 ++++++++++++++--- .../client/WebSocketConnectionManager.java | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java index 147938331c0..ade1372af78 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,9 +49,20 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { private final Object lifecycleMonitor = new Object(); + /** + * Constructor with a URI template and variables. + */ public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) { - this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand( - uriVariables).encode().toUri(); + this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri(); + } + + /** + * Constructor with a prepared {@link URI}. + * @param uri the url to connect to + * @since 6.0.5 + */ + public ConnectionManagerSupport(URI uri) { + this.uri = uri; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java index 326c693d6f5..85b210ba6d3 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java @@ -16,6 +16,7 @@ package org.springframework.web.socket.client; +import java.net.URI; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -48,6 +49,9 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { private final WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); + /** + * Constructor with the client to use and a handler to handle messages with. + */ public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) { @@ -56,6 +60,17 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { this.webSocketHandler = decorateWebSocketHandler(webSocketHandler); } + /** + * Variant of {@link #WebSocketConnectionManager(WebSocketClient, WebSocketHandler, String, Object...)} + * with a prepared {@link URI}. + * @since 6.0.5 + */ + public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, URI uri) { + super(uri); + this.client = client; + this.webSocketHandler = decorateWebSocketHandler(webSocketHandler); + } + /** * Set the sub-protocols to use. If configured, specified sub-protocols will be