This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.25.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.25.x by this push: new 9d400fe CAMEL-15974: Fix RAW parameters resolution in HttpSendDynamicAware (#4812) 9d400fe is described below commit 9d400fe750d2edf7388cac4dcadeec218436a000 Author: iliya-gr <iliya...@gmail.com> AuthorDate: Wed Dec 23 11:08:04 2020 +0300 CAMEL-15974: Fix RAW parameters resolution in HttpSendDynamicAware (#4812) --- .../camel/http/common/HttpSendDynamicAware.java | 6 +- .../HttpSendDynamicAwareRawParameterTest.java | 80 ++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java index 4b86008..438866b 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpSendDynamicAware.java @@ -97,8 +97,10 @@ public class HttpSendDynamicAware implements SendDynamicAware { String path = hostAndPath[1]; String query = null; if (!entry.getLenientProperties().isEmpty()) { + Map<String, Object> lenientProperties = new LinkedHashMap<>(entry.getLenientProperties()); + URISupport.resolveRawParameterValues(lenientProperties); // all lenient properties can be dynamic and provided in the HTTP_QUERY header - query = URISupport.createQueryString(new LinkedHashMap<>(entry.getLenientProperties())); + query = URISupport.createQueryString(lenientProperties); } if (query == null && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Exchange.HTTP_QUERY))) { @@ -166,5 +168,5 @@ public class HttpSendDynamicAware implements SendDynamicAware { // no context path return new String[]{u, null}; } - + } diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSendDynamicAwareRawParameterTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSendDynamicAwareRawParameterTest.java new file mode 100644 index 0000000..801511b --- /dev/null +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpSendDynamicAwareRawParameterTest.java @@ -0,0 +1,80 @@ +/* + * 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.http4; + +import org.apache.camel.Exchange; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http4.handler.BasicValidationHandler; +import org.apache.http.impl.bootstrap.HttpServer; +import org.apache.http.impl.bootstrap.ServerBootstrap; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class HttpSendDynamicAwareRawParameterTest extends BaseHttpTest { + + private HttpServer localServer; + + @Before + @Override + public void setUp() throws Exception { + localServer = ServerBootstrap.bootstrap() + .setHttpProcessor(getBasicHttpProcessor()) + .setConnectionReuseStrategy(getConnectionReuseStrategy()) + .setResponseFactory(getHttpResponseFactory()) + .setExpectationVerifier(getHttpExpectationVerifier()) + .setSslContext(getSSLContext()) + .registerHandler("/dynamicAware", new BasicValidationHandler("GET", "par1=val1&par2=val2", null, null)).create(); + localServer.start(); + + super.setUp(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + + if (localServer != null) { + localServer.stop(); + } + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:dynamicAwareWithRaw") + .toD("http4://localhost:" + localServer.getLocalPort() + "/dynamicAware?par1=RAW(${headers.par1})&par2=RAW{${headers.par2}}"); + } + }; + } + + @Test + public void testDynamicAwareHeadersQuery() throws Exception { + Exchange e = fluentTemplate + .to("direct:dynamicAwareWithRaw") + .withHeader("par1", "val1") + .withHeader("par2", "val2") + .send(); + + assertEquals("/dynamicAware", e.getIn().getHeader(Exchange.HTTP_PATH)); + assertEquals("par1=val1&par2=val2", e.getIn().getHeader(Exchange.HTTP_QUERY)); + } +}