CAMEL-7427 camel-netty-http endpoint should skip reading the form body if it is bridgeEndpoint
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2cf4c461 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2cf4c461 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2cf4c461 Branch: refs/heads/master Commit: 2cf4c461c960c80b56dee538fe81d10929a4a0a9 Parents: ab97041 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Fri May 9 16:45:02 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Fri May 9 16:54:03 2014 +0800 ---------------------------------------------------------------------- .../netty/http/DefaultNettyHttpBinding.java | 4 +++- .../netty/http/NettyHttpComponent.java | 1 + .../http/handlers/HttpServerChannelHandler.java | 1 + ...NettyHttpBridgeRouteUsingHttpClientTest.java | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2cf4c461/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java index 00eda1e..23cae6c 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java @@ -195,8 +195,10 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable { } // if body is application/x-www-form-urlencoded then extract the body as query string and append as headers + // if it is a bridgeEndpoint we need to skip this part of work if (request.getMethod().getName().equals("POST") && request.getHeader(Exchange.CONTENT_TYPE) != null - && request.getHeader(Exchange.CONTENT_TYPE).startsWith(NettyHttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED)) { + && request.getHeader(Exchange.CONTENT_TYPE).startsWith(NettyHttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED) + && !configuration.isBridgeEndpoint()) { String charset = "UTF-8"; http://git-wip-us.apache.org/repos/asf/camel/blob/2cf4c461/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java index e4142d7..07c9923 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java @@ -93,6 +93,7 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt // create the address uri which includes the remainder parameters (which is not configuration parameters for this component) URI u = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(remaining)); + String addressUri = URISupport.createRemainingURI(u, parameters).toString(); NettyHttpEndpoint answer = new NettyHttpEndpoint(addressUri, this, config); http://git-wip-us.apache.org/repos/asf/camel/blob/2cf4c461/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java index 71a8aec..06bc81b 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java @@ -269,6 +269,7 @@ public class HttpServerChannelHandler extends ServerChannelHandler { protected void beforeProcess(Exchange exchange, MessageEvent messageEvent) { if (consumer.getConfiguration().isBridgeEndpoint()) { exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); + exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE); } } http://git-wip-us.apache.org/repos/asf/camel/blob/2cf4c461/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java index ff7958b..1dc92f5 100644 --- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBridgeRouteUsingHttpClientTest.java @@ -19,6 +19,7 @@ package org.apache.camel.component.netty.http; import java.io.ByteArrayInputStream; import org.apache.camel.Exchange; +import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.RuntimeCamelException; import org.apache.camel.builder.RouteBuilder; @@ -45,6 +46,12 @@ public class NettyHttpBridgeRouteUsingHttpClientTest extends BaseNettyTest { assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException); } } + + @Test + public void testSendFormRequestMessage() throws Exception { + String out = template.requestBodyAndHeader("http://localhost:" + port2 + "/form", "username=abc&pass=password", Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded", String.class); + assertEquals("Get a wrong response message", "username=abc&pass=password", out); + } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @@ -65,6 +72,19 @@ public class NettyHttpBridgeRouteUsingHttpClientTest extends BaseNettyTest { .to("http://localhost:" + port1 + "?throwExceptionOnFailure=false&bridgeEndpoint=true"); from("netty-http:http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc); + + // check the from request + from("netty-http:http://localhost:" + port2 + "/form?bridgeEndpoint=true") + .process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + // just take out the message body and send it back + Message in = exchange.getIn(); + String request = in.getBody(String.class); + exchange.getOut().setBody(request); + } + + }); } }; }