From 8462ca4c7657a9f88d66694cb0bb9ac7c3c1faf4 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 9 Jul 2024 13:20:40 +0200 Subject: [PATCH] WebSockets Next - client: use 443 if port is undefined and https is set (cherry picked from commit 5e4e3ba225a1583f9e1f2b7305b216632531aae9) --- .../runtime/BasicWebSocketConnectorImpl.java | 5 +---- .../next/runtime/WebSocketConnectorBase.java | 18 ++++++++++++++++++ .../next/runtime/WebSocketConnectorImpl.java | 5 +---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/BasicWebSocketConnectorImpl.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/BasicWebSocketConnectorImpl.java index fb33732ca6c47..7d2487783ccf1 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/BasicWebSocketConnectorImpl.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/BasicWebSocketConnectorImpl.java @@ -117,10 +117,7 @@ public Uni connect() { // TODO would it make sense to share clients? WebSocketClient client = vertx.createWebSocketClient(populateClientOptions()); - WebSocketConnectOptions connectOptions = new WebSocketConnectOptions() - .setSsl(baseUri.getScheme().equals("https")) - .setHost(baseUri.getHost()) - .setPort(baseUri.getPort()); + WebSocketConnectOptions connectOptions = newConnectOptions(baseUri); StringBuilder requestUri = new StringBuilder(); String mergedPath = mergePath(baseUri.getPath(), replacePathParameters(path)); requestUri.append(mergedPath); diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorBase.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorBase.java index ee098d6a43d16..1556899636c9f 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorBase.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorBase.java @@ -21,6 +21,7 @@ import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.WebSocketClientOptions; +import io.vertx.core.http.WebSocketConnectOptions; import io.vertx.core.net.SSLOptions; abstract class WebSocketConnectorBase> { @@ -191,4 +192,21 @@ protected WebSocketClientOptions populateClientOptions() { } return clientOptions; } + + protected WebSocketConnectOptions newConnectOptions(URI serverEndpointUri) { + WebSocketConnectOptions connectOptions = new WebSocketConnectOptions() + .setSsl(isHttps(serverEndpointUri)) + .setHost(serverEndpointUri.getHost()); + if (serverEndpointUri.getPort() != -1) { + connectOptions.setPort(serverEndpointUri.getPort()); + } else if (isHttps(serverEndpointUri)) { + // If port is undefined and https is used then use 443 by default + connectOptions.setPort(443); + } + return connectOptions; + } + + protected boolean isHttps(URI uri) { + return "https".equals(uri.getScheme()); + } } diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorImpl.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorImpl.java index 359a400f5160a..1b6d9a6af32ec 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorImpl.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/WebSocketConnectorImpl.java @@ -73,10 +73,7 @@ public Uni connect() { throw new WebSocketClientException(e); } - WebSocketConnectOptions connectOptions = new WebSocketConnectOptions() - .setSsl(serverEndpointUri.getScheme().equals("https")) - .setHost(serverEndpointUri.getHost()) - .setPort(serverEndpointUri.getPort()); + WebSocketConnectOptions connectOptions = newConnectOptions(serverEndpointUri); StringBuilder uri = new StringBuilder(); if (serverEndpointUri.getPath() != null) { uri.append(serverEndpointUri.getRawPath());