Repository: camel Updated Branches: refs/heads/camel-2.16.x dbae5f1b8 -> 2314e218d refs/heads/master 8fd524944 -> a0412598b
CAMEL-9640 - Query string gets decoded when bridging from netty*-http to netty*-http Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a0412598 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a0412598 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a0412598 Branch: refs/heads/master Commit: a0412598b97c51f09dc2567058122034f035a140 Parents: 8fd5249 Author: Tadayoshi Sato <sato.tadayo...@gmail.com> Authored: Wed Feb 24 20:37:21 2016 +0900 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Feb 25 10:36:44 2016 +0100 ---------------------------------------------------------------------- .../apache/camel/http/common/HttpHelper.java | 2 +- .../component/netty/http/NettyHttpHelper.java | 8 +++- .../netty/http/NettyHttpProducerBridgeTest.java | 41 ++++++++++++++++++++ .../component/netty4/http/NettyHttpHelper.java | 8 +++- .../http/NettyHttpProducerBridgeTest.java | 41 ++++++++++++++++++++ 5 files changed, 95 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a0412598/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java index 2365eb6..08f2e2d 100644 --- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java +++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java @@ -320,7 +320,7 @@ public final class HttpHelper { if (queryString == null) { queryString = endpoint.getHttpUri().getRawQuery(); } - // We should user the query string from the HTTP_URI header + // We should use the query string from the HTTP_URI header if (queryString == null) { queryString = uri.getRawQuery(); } http://git-wip-us.apache.org/repos/asf/camel/blob/a0412598/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java index 45cc8f2..cea0b0a4 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java @@ -236,8 +236,12 @@ public final class NettyHttpHelper { */ public static URI createURI(Exchange exchange, String url, NettyHttpEndpoint endpoint) throws URISyntaxException { URI uri = new URI(url); - // is a query string provided in the endpoint URI or in a header (header overrules endpoint) - String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); + // is a query string provided in the endpoint URI or in a header + // (header overrules endpoint, raw query header overrules query header) + String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class); + if (queryString == null) { + queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); + } if (queryString == null) { // use raw as we encode just below queryString = uri.getRawQuery(); http://git-wip-us.apache.org/repos/asf/camel/blob/a0412598/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java index f6e454c..6237093 100644 --- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgeTest.java @@ -16,13 +16,17 @@ */ package org.apache.camel.component.netty.http; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.Test; public class NettyHttpProducerBridgeTest extends BaseNettyTest { private int port1; private int port2; + private int port3; @Test public void testProxy() throws Exception { @@ -30,6 +34,39 @@ public class NettyHttpProducerBridgeTest extends BaseNettyTest { assertEquals("Bye World", reply); } + @Test + public void testBridgeWithQuery() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:query"); + mock.message(0).header(Exchange.HTTP_RAW_QUERY).isEqualTo("x=%3B"); + mock.message(0).header(Exchange.HTTP_QUERY).isEqualTo("x=;"); + + template.request("netty-http:http://localhost:" + port3 + "/query?bridgeEndpoint=true", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/"); + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=%3B"); + } + }); + assertMockEndpointsSatisfied(); + } + + @Test + public void testBridgeWithRawQueryAndQuery() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:query"); + mock.message(0).header(Exchange.HTTP_RAW_QUERY).isEqualTo("x=%3B"); + mock.message(0).header(Exchange.HTTP_QUERY).isEqualTo("x=;"); + + template.request("netty-http:http://localhost:" + port3 + "/query?bridgeEndpoint=true", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/"); + exchange.getIn().setHeader(Exchange.HTTP_RAW_QUERY, "x=%3B"); + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=;"); + } + }); + assertMockEndpointsSatisfied(); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @@ -37,12 +74,16 @@ public class NettyHttpProducerBridgeTest extends BaseNettyTest { public void configure() throws Exception { port1 = getPort(); port2 = getNextPort(); + port3 = getNextPort(); from("netty-http:http://0.0.0.0:" + port1 + "/foo") .to("netty-http:http://localhost:" + port2 + "/bar?bridgeEndpoint=true&throwExceptionOnFailure=false"); from("netty-http:http://0.0.0.0:" + port2 + "/bar") .transform().simple("Bye ${body}"); + + from("netty-http:http://0.0.0.0:" + port3 + "/query") + .to("mock:query"); } }; } http://git-wip-us.apache.org/repos/asf/camel/blob/a0412598/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java index 330d79c..e5d3c4f 100644 --- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java +++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpHelper.java @@ -236,8 +236,12 @@ public final class NettyHttpHelper { */ public static URI createURI(Exchange exchange, String url, NettyHttpEndpoint endpoint) throws URISyntaxException { URI uri = new URI(url); - // is a query string provided in the endpoint URI or in a header (header overrules endpoint) - String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); + // is a query string provided in the endpoint URI or in a header + // (header overrules endpoint, raw query header overrules query header) + String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class); + if (queryString == null) { + queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); + } if (queryString == null) { // use raw as we encode just below queryString = uri.getRawQuery(); http://git-wip-us.apache.org/repos/asf/camel/blob/a0412598/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java index ecee0c5..4b2cf7f 100644 --- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java +++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgeTest.java @@ -16,13 +16,17 @@ */ package org.apache.camel.component.netty4.http; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.Test; public class NettyHttpProducerBridgeTest extends BaseNettyTest { private int port1; private int port2; + private int port3; @Test public void testProxy() throws Exception { @@ -30,6 +34,39 @@ public class NettyHttpProducerBridgeTest extends BaseNettyTest { assertEquals("Bye World", reply); } + @Test + public void testBridgeWithQuery() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:query"); + mock.message(0).header(Exchange.HTTP_RAW_QUERY).isEqualTo("x=%3B"); + mock.message(0).header(Exchange.HTTP_QUERY).isEqualTo("x=;"); + + template.request("netty4-http:http://localhost:" + port3 + "/query?bridgeEndpoint=true", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/"); + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=%3B"); + } + }); + assertMockEndpointsSatisfied(); + } + + @Test + public void testBridgeWithRawQueryAndQuery() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:query"); + mock.message(0).header(Exchange.HTTP_RAW_QUERY).isEqualTo("x=%3B"); + mock.message(0).header(Exchange.HTTP_QUERY).isEqualTo("x=;"); + + template.request("netty4-http:http://localhost:" + port3 + "/query?bridgeEndpoint=true", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/"); + exchange.getIn().setHeader(Exchange.HTTP_RAW_QUERY, "x=%3B"); + exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=;"); + } + }); + assertMockEndpointsSatisfied(); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @@ -37,12 +74,16 @@ public class NettyHttpProducerBridgeTest extends BaseNettyTest { public void configure() throws Exception { port1 = getPort(); port2 = getNextPort(); + port3 = getNextPort(); from("netty4-http:http://0.0.0.0:" + port1 + "/foo") .to("netty4-http:http://localhost:" + port2 + "/bar?bridgeEndpoint=true&throwExceptionOnFailure=false"); from("netty4-http:http://0.0.0.0:" + port2 + "/bar") .transform().simple("Bye ${body}"); + + from("netty4-http:http://0.0.0.0:" + port3 + "/query") + .to("mock:query"); } }; }