From eb18d0ee2095428cd9b381bb26a8d64893520098 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 29 Jul 2024 09:58:59 +0200 Subject: [PATCH] WebSockets Next client: support string params for connector.baseUri() - resolves #42182 --- .../next/test/client/BasicConnectorTest.java | 2 +- .../next/test/client/ClientAutoPingIntervalTest.java | 2 +- .../websockets/next/BasicWebSocketConnector.java | 10 ++++++++++ .../io/quarkus/websockets/next/WebSocketConnector.java | 10 ++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/BasicConnectorTest.java b/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/BasicConnectorTest.java index 6bf3377d2fba6..ac622096e3029 100644 --- a/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/BasicConnectorTest.java +++ b/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/BasicConnectorTest.java @@ -47,7 +47,7 @@ public class BasicConnectorTest { @Test void testClient() throws InterruptedException { - assertThrows(NullPointerException.class, () -> connector.baseUri(null)); + assertThrows(IllegalArgumentException.class, () -> connector.baseUri("foo\\")); assertThrows(NullPointerException.class, () -> connector.path(null)); assertThrows(NullPointerException.class, () -> connector.addHeader(null, "foo")); assertThrows(NullPointerException.class, () -> connector.addHeader("foo", null)); diff --git a/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/ClientAutoPingIntervalTest.java b/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/ClientAutoPingIntervalTest.java index 52b4734273670..29bac6a1b016a 100644 --- a/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/ClientAutoPingIntervalTest.java +++ b/extensions/websockets-next/deployment/src/test/java/io/quarkus/websockets/next/test/client/ClientAutoPingIntervalTest.java @@ -37,7 +37,7 @@ public class ClientAutoPingIntervalTest { @Test public void testPingPong() throws InterruptedException, ExecutionException { - connector.baseUri(uri).connectAndAwait(); + connector.baseUri(uri.toString()).connectAndAwait(); // Ping messages are sent automatically assertTrue(ClientEndpoint.PONG.await(5, TimeUnit.SECONDS)); } diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BasicWebSocketConnector.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BasicWebSocketConnector.java index b1e21c9b12966..98ab5ac1596e2 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BasicWebSocketConnector.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BasicWebSocketConnector.java @@ -39,6 +39,16 @@ static BasicWebSocketConnector create() { */ BasicWebSocketConnector baseUri(URI uri); + /** + * Set the base URI. + * + * @param baseUri + * @return self + */ + default BasicWebSocketConnector baseUri(String baseUri) { + return baseUri(URI.create(baseUri)); + } + /** * Set the path that should be appended to the path of the URI set by {@link #baseUri(URI)}. *

diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocketConnector.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocketConnector.java index 257094e31fe23..06f91ddf3e919 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocketConnector.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocketConnector.java @@ -27,6 +27,16 @@ public interface WebSocketConnector { */ WebSocketConnector baseUri(URI baseUri); + /** + * Set the base URI. + * + * @param baseUri + * @return self + */ + default WebSocketConnector baseUri(String baseUri) { + return baseUri(URI.create(baseUri)); + } + /** * Set the path param. *