You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/09/18 18:21:00 UTC
[camel] branch camel-3.4.x updated: Backporting to 3.4.x for
CAMEL-15547 Wrong URI with http dsl and query parameters (#4252)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.4.x by this push:
new 4f50269 Backporting to 3.4.x for CAMEL-15547 Wrong URI with http dsl and query parameters (#4252)
4f50269 is described below
commit 4f50269637c8e3172b8f8da217e987c712464d41
Author: Chandrakant Hardahe <ch...@gmail.com>
AuthorDate: Fri Sep 18 23:50:29 2020 +0530
Backporting to 3.4.x for CAMEL-15547 Wrong URI with http dsl and query parameters (#4252)
Co-authored-by: Chandrakant Hardahe <ch...@chardahe.pnq.csb>
---
.../builder/endpoint/AbstractEndpointBuilder.java | 6 ++-
.../builder/endpoint/EndpointQueryParamTest.java | 62 ++++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
index ad68878..34311e9 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
@@ -102,7 +102,11 @@ public class AbstractEndpointBuilder {
try {
// build query string from parameters
String query = URISupport.createQueryString(params, encode);
- answer = new NormalizedUri(targetScheme + "://" + targetPath + "?" + query);
+ if(targetPath.contains("?")) {
+ answer = new NormalizedUri(targetScheme + "://" + targetPath + "&" + query);
+ } else {
+ answer = new NormalizedUri(targetScheme + "://" + targetPath + "?" + query);
+ }
} catch (URISyntaxException e) {
throw RuntimeCamelException.wrapRuntimeCamelException(e);
}
diff --git a/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/EndpointQueryParamTest.java b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/EndpointQueryParamTest.java
new file mode 100644
index 0000000..96c308b
--- /dev/null
+++ b/core/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/EndpointQueryParamTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.builder.endpoint;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class EndpointQueryParamTest extends CamelTestSupport {
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("jetty").host("localhost").port(9999);
+ rest().get("path/xyz")
+ .to("log:myLogger?level=INFO&showAll=true")
+ .to("mock:result");
+ from(direct("test"))
+ .to(http("localhost:9999/path/xyz?param1=1¶m2=2").httpMethod("GET"));
+ from(direct("test2"))
+ .to("http://localhost:9999/path/xyz?param1=1¶m2=2&httpMethod=GET");
+ }
+ };
+ }
+
+ @Test
+ public void testRoute() throws InterruptedException {
+ MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
+
+ mockEndpoint.expectedHeaderReceived("param1", "1");
+ mockEndpoint.expectedHeaderReceived("param2", "2");
+
+ template.sendBody("direct:test2", null);
+ mockEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testEndpointDslRoute() throws InterruptedException {
+ MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
+ mockEndpoint.expectedHeaderReceived("param1", "1");
+ mockEndpoint.expectedHeaderReceived("param2", "2");
+
+ template.sendBody("direct:test", null);
+ mockEndpoint.assertIsSatisfied();
+ }
+}