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 5453fe8005b1 CAMEL-27482: camel-vertx-websocket - send the query of a
remote WebSocket URI as it is encoded (#30688)
5453fe8005b1 is described below
commit 5453fe8005b183147c6e14d974bbe88c40c25935
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 24 07:45:27 2026 +0100
CAMEL-27482: camel-vertx-websocket - send the query of a remote WebSocket
URI as it is encoded (#30688)
The client (consumeAsClient, and a producer to a remote server) built the
handshake request URI with
URISupport.pathAndQueryOf, which uses the decoded path and query. A RAW
value with + or & was sent decoded: the server
read + as a space, and & split the value. When the component filled in a
default host, port or path, the
multi-argument URI constructor decoded the query too.
The request URI is now the raw path and query, and the default host, port
and path keep the raw query.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../catalog/docs/vertx-websocket-component.adoc | 5 +
.../src/main/docs/vertx-websocket-component.adoc | 5 +
.../vertx/websocket/VertxWebsocketComponent.java | 10 +-
.../vertx/websocket/VertxWebsocketEndpoint.java | 16 +++-
.../VertxWebsocketClientRawQueryTest.java | 103 +++++++++++++++++++++
5 files changed, 133 insertions(+), 6 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/vertx-websocket-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/vertx-websocket-component.adoc
index ca9acb7e6b8d..7d321ee2269c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/vertx-websocket-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/vertx-websocket-component.adoc
@@ -138,6 +138,11 @@ Some servers only send messages to a client that asked for
them, such as a feed
message: "Got WebSocket message ${body}"
----
+The query parameters of the URI that are not options of the component are sent
to the remote server. Like any endpoint
+URI, Camel decodes the URI before the component reads it, so write a value
that contains `+`, `&` or `%` (such as a
+token or a signature) as a raw value, for example `token=RAW(a+b/c=)`. It then
reaches the server as written. See
+xref:manual::endpoint.adoc#_configuring_parameter_values_using_raw_values_such_as_passwords[raw
values].
+
=== Path & query parameters
The WebSocket server consumer supports the configuration of parameterized
paths. The path parameter value will be set
diff --git
a/components/camel-vertx/camel-vertx-websocket/src/main/docs/vertx-websocket-component.adoc
b/components/camel-vertx/camel-vertx-websocket/src/main/docs/vertx-websocket-component.adoc
index ca9acb7e6b8d..7d321ee2269c 100644
---
a/components/camel-vertx/camel-vertx-websocket/src/main/docs/vertx-websocket-component.adoc
+++
b/components/camel-vertx/camel-vertx-websocket/src/main/docs/vertx-websocket-component.adoc
@@ -138,6 +138,11 @@ Some servers only send messages to a client that asked for
them, such as a feed
message: "Got WebSocket message ${body}"
----
+The query parameters of the URI that are not options of the component are sent
to the remote server. Like any endpoint
+URI, Camel decodes the URI before the component reads it, so write a value
that contains `+`, `&` or `%` (such as a
+token or a signature) as a raw value, for example `token=RAW(a+b/c=)`. It then
reaches the server as written. See
+xref:manual::endpoint.adoc#_configuring_parameter_values_using_raw_values_such_as_passwords[raw
values].
+
=== Path & query parameters
The WebSocket server consumer supports the configuration of parameterized
paths. The path parameter value will be set
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 4047958ed436..99bd0cabe046 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
@@ -118,10 +118,12 @@ public class VertxWebsocketComponent extends
DefaultComponent implements SSLCont
path = "/";
}
- websocketURI = new URI(
- websocketURI.getScheme(), websocketURI.getUserInfo(),
- host, port, path, websocketURI.getQuery(),
- websocketURI.getFragment());
+ // keep the query as it is encoded: the multi-argument URI
constructor would decode %2B and %26 of a RAW value
+ String rawQuery = websocketURI.getRawQuery();
+ websocketURI = new URI(websocketURI.getScheme(),
websocketURI.getUserInfo(), host, port, path, null, null);
+ if (rawQuery != null) {
+ websocketURI = URISupport.createURIWithQuery(websocketURI,
rawQuery);
+ }
}
configuration.setWebsocketURI(websocketURI);
diff --git
a/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpoint.java
b/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpoint.java
index ab2fa1a3aa2d..813524cc4c92 100644
---
a/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpoint.java
+++
b/components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpoint.java
@@ -50,7 +50,6 @@ import org.apache.camel.support.DefaultEndpoint;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -352,7 +351,7 @@ public class VertxWebsocketEndpoint extends DefaultEndpoint
implements EndpointS
URI websocketURI = configuration.getWebsocketURI();
WebSocketConnectOptions connectOptions = new WebSocketConnectOptions();
connectOptions.setHost(websocketURI.getHost());
- connectOptions.setURI(URISupport.pathAndQueryOf(websocketURI));
+ connectOptions.setURI(rawPathAndQuery(websocketURI));
connectOptions.setSsl(options.isSsl() ||
websocketURI.getScheme().length() == 3);
if (websocketURI.getPort() > 0) {
@@ -381,6 +380,19 @@ public class VertxWebsocketEndpoint extends
DefaultEndpoint implements EndpointS
return connectOptions;
}
+ /**
+ * The path and query of the request to the remote server, as they are
encoded in the URI, so a RAW value with + or
+ * & reaches the server as written. URISupport.pathAndQueryOf uses the
decoded path and query.
+ */
+ static String rawPathAndQuery(URI uri) {
+ String path = uri.getRawPath();
+ if (ObjectHelper.isEmpty(path)) {
+ path = "/";
+ }
+ String query = uri.getRawQuery();
+ return ObjectHelper.isNotEmpty(query) ? path + "?" + query : path;
+ }
+
protected Map<VertxWebsocketHostKey, VertxWebsocketHost>
getVertxHostRegistry() {
return getComponent().getVertxHostRegistry();
}
diff --git
a/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketClientRawQueryTest.java
b/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketClientRawQueryTest.java
new file mode 100644
index 000000000000..6889e17094f1
--- /dev/null
+++
b/components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketClientRawQueryTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.vertx.websocket;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+import io.netty.handler.codec.http.QueryStringDecoder;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpServer;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The query of a remote WebSocket URI reaches the server as written, with RAW
values that contain +, & and spaces. The
+ * server is a plain Vert.x HTTP server that keeps the query of each handshake
by path, and sends it back.
+ */
+class VertxWebsocketClientRawQueryTest extends VertxWebSocketTestSupport {
+
+ private final Map<String, String> queries = new ConcurrentHashMap<>();
+ private Vertx serverVertx;
+
+ @Override
+ protected void setupResources() throws Exception {
+ serverVertx = Vertx.vertx();
+ HttpServer server = serverVertx.createHttpServer();
+ server.webSocketHandler(webSocket -> {
+ queries.put(webSocket.path(), String.valueOf(webSocket.query()));
+ webSocket.writeTextMessage(String.valueOf(webSocket.query()));
+ });
+ server.listen(port.getPort(),
"localhost").toCompletionStage().toCompletableFuture().get(10,
TimeUnit.SECONDS);
+ }
+
+ @Override
+ protected void cleanupResources() throws Exception {
+ if (serverVertx != null) {
+
serverVertx.close().toCompletionStage().toCompletableFuture().get(10,
TimeUnit.SECONDS);
+ }
+ }
+
+ @Test
+ void clientConsumerSendsTheRawValuesAsWritten() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:consumer");
+ mock.expectedMessageCount(1);
+ MockEndpoint.assertIsSatisfied(context, 20, TimeUnit.SECONDS);
+
+
assertParameters(mock.getReceivedExchanges().get(0).getMessage().getBody(String.class));
+ }
+
+ @Test
+ void producerSendsTheRawValuesAsWritten() {
+ // no path in the endpoint URI: the component fills in "/" and must
keep the query as it is encoded
+ template.sendBody("direct:produce", "Hello");
+
+ await().atMost(20, TimeUnit.SECONDS).until(() ->
queries.containsKey("/"));
+ assertParameters(queries.get("/"));
+ }
+
+ private static void assertParameters(String query) {
+ Map<String, List<String>> parameters = new QueryStringDecoder(query,
false).parameters();
+ assertEquals(List.of("a+b"), parameters.get("token"), "query " +
query);
+ assertEquals(List.of("x&y=z"), parameters.get("sig"), "query " +
query);
+ assertEquals(List.of("a b"), parameters.get("text"), "query " + query);
+ assertEquals(3, parameters.size(), "query " + query);
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
fromF("vertx-websocket:localhost:%d/consumer?consumeAsClient=true"
+ + "&token=RAW(a+b)&sig=RAW(x&y=z)&text=RAW(a b)",
+ port.getPort())
+ .to("mock:consumer");
+
+ from("direct:produce")
+
.toF("vertx-websocket:localhost:%d?token=RAW(a+b)&sig=RAW(x&y=z)&text=RAW(a
b)", port.getPort());
+ }
+ };
+ }
+}