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());