This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new be07323653b Fix camel-vertx-websocket endpoint instantiation when
connection to remote websocket server (#13707)
be07323653b is described below
commit be07323653b6ebae0b0d5933bf6e2da94d85965b
Author: Alexis SEGURA <[email protected]>
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 <[email protected]>
---
.../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() {