This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-4.4.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.4.x by this push: new 1714311c76b Fix camel-vertx-websocket endpoint instantiation when connection to remote websocket server (#13707) 1714311c76b is described below commit 1714311c76b7fa62e1e93b147687f43af6ab0dc6 Author: Alexis SEGURA <alex.segur...@gmail.com> AuthorDate: Sun Apr 7 18:41:31 2024 +0200 Fix camel-vertx-websocket endpoint instantiation when connection to remote websocket server (#13707) Previously, endpoint properties were set after configuring the websocketURI. As a result, when using the endpoint with consumeAsClient option, endpoint properties were passed as query param (consumeAsClient for example). Some APIs reject upgrade to websocket when unknown parameters are passed in the call. The purpose of this commit is to set endpoint properties before configuring websocketURI. So properties are binded and removed from the parameters map before configuring the websocke [...] Co-authored-by: Alexis SEGURA <alexis.seg...@akt.io> --- .../component/vertx/websocket/VertxWebsocketComponent.java | 13 +++++++------ .../websocket/VertxWebsocketEndpointConfigurationTest.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketComponent.java b/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketComponent.java index 4a793f43f03..f29295371c7 100644 --- a/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketComponent.java +++ b/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketComponent.java @@ -76,6 +76,13 @@ public class VertxWebsocketComponent extends DefaultComponent implements SSLCont } } + VertxWebsocketConfiguration configuration = new VertxWebsocketConfiguration(); + configuration.setAllowOriginHeader(isAllowOriginHeader()); + configuration.setOriginHeaderUrl(getOriginHeaderUrl()); + + VertxWebsocketEndpoint endpoint = createEndpointInstance(uri, configuration); + setProperties(endpoint, parameters); + URI endpointUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(wsUri)); URI websocketURI = URISupport.createRemainingURI(endpointUri, parameters); @@ -102,13 +109,7 @@ public class VertxWebsocketComponent extends DefaultComponent implements SSLCont websocketURI.getFragment()); } - VertxWebsocketConfiguration configuration = new VertxWebsocketConfiguration(); configuration.setWebsocketURI(websocketURI); - configuration.setAllowOriginHeader(isAllowOriginHeader()); - configuration.setOriginHeaderUrl(getOriginHeaderUrl()); - - VertxWebsocketEndpoint endpoint = createEndpointInstance(uri, configuration); - setProperties(endpoint, parameters); if (configuration.getSslContextParameters() == null) { configuration.setSslContextParameters(retrieveGlobalSslContextParameters()); diff --git a/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpointConfigurationTest.java b/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpointConfigurationTest.java index 234378e459c..810a5edfdf5 100644 --- a/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpointConfigurationTest.java +++ b/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpointConfigurationTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.vertx.websocket; +import java.net.URI; + import io.vertx.core.MultiMap; import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpServerOptions; @@ -101,6 +103,17 @@ public class VertxWebsocketEndpointConfigurationTest extends VertxWebSocketTestS assertEquals(originUrl, originHeaderValue); } + @Test + void testPropertiesBinding() { + String testQueryParam = "testParam=hello"; + String endpointParams = "consumeAsClient=true&maxReconnectAttempts=2"; + VertxWebsocketEndpoint endpoint + = context.getEndpoint("vertx-websocket:foo.bar.com/test?" + endpointParams + "&" + testQueryParam, + VertxWebsocketEndpoint.class); + URI websocketURI = endpoint.getConfiguration().getWebsocketURI(); + assertEquals(testQueryParam, websocketURI.getQuery(), "Query parameters are not correctly set in the in websocketURI."); + } + @Override protected RoutesBuilder createRouteBuilder() { return new RouteBuilder() {