CAMEL-7426 camel-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/e7b01af0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e7b01af0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e7b01af0 Branch: refs/heads/camel-2.12.x Commit: e7b01af0deda0bf642a72044cd41959e48a82338 Parents: 32b6f77 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Fri May 9 16:38:30 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Fri May 9 16:58:10 2014 +0800 ---------------------------------------------------------------------- .../main/java/org/apache/camel/Exchange.java | 1 + .../camel/component/http/CamelServlet.java | 1 + .../component/http/DefaultHttpBinding.java | 6 ++++-- .../camel/component/http/HttpMessage.java | 6 ++++++ .../jetty/CamelContinuationServlet.java | 1 + .../component/jetty/HttpProxyRouteTest.java | 21 ++++++++++++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/camel-core/src/main/java/org/apache/camel/Exchange.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java index 6b909da..2c62949 100644 --- a/camel-core/src/main/java/org/apache/camel/Exchange.java +++ b/camel-core/src/main/java/org/apache/camel/Exchange.java @@ -178,6 +178,7 @@ public interface Exchange { String SOAP_ACTION = "CamelSoapAction"; String SKIP_GZIP_ENCODING = "CamelSkipGzipEncoding"; + String SKIP_WWW_FORM_URLENCODED = "CamelSkipWwwFormUrlEncoding"; String SLIP_ENDPOINT = "CamelSlipEndpoint"; String SPLIT_INDEX = "CamelSplitIndex"; String SPLIT_COMPLETE = "CamelSplitComplete"; http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java index a56257c..cbfded3 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java @@ -89,6 +89,7 @@ public class CamelServlet extends HttpServlet { if (consumer.getEndpoint().isBridgeEndpoint()) { exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); + exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE); } if (consumer.getEndpoint().isDisableStreamCache()) { exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE); http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java index dd74c43..49b9a47 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java @@ -171,9 +171,11 @@ public class DefaultHttpBinding implements HttpBinding { } LOG.trace("HTTP method {} with Content-Type {}", request.getMethod(), request.getContentType()); - + Boolean flag = message.getHeader(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.class); + boolean skipWwwFormUrlEncoding = flag != null ? flag : false; if (request.getMethod().equals("POST") && request.getContentType() != null - && request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED)) { + && request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED) + && !skipWwwFormUrlEncoding) { String charset = request.getCharacterEncoding(); if (charset == null) { charset = "UTF-8"; http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java ---------------------------------------------------------------------- diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java index 80a6614..8218f2d 100644 --- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java +++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java @@ -40,6 +40,12 @@ public class HttpMessage extends DefaultMessage { // Put the request and response into the message header this.setHeader(Exchange.HTTP_SERVLET_REQUEST, request); this.setHeader(Exchange.HTTP_SERVLET_RESPONSE, response); + + // Check the setting of exchange + Boolean flag = exchange.getProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.class); + if (flag != null && flag) { + this.setHeader(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE); + } // use binding to read the request allowing end users to use their // implementation of the binding http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java index de0bb8b..4f274b3 100644 --- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java +++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java @@ -105,6 +105,7 @@ public class CamelContinuationServlet extends CamelServlet { if (consumer.getEndpoint().isBridgeEndpoint()) { exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); + exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE); } if (consumer.getEndpoint().isDisableStreamCache()) { exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE); http://git-wip-us.apache.org/repos/asf/camel/blob/e7b01af0/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java index da93bce..e0188f6 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java @@ -17,6 +17,8 @@ package org.apache.camel.component.jetty; import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.util.StopWatch; import org.apache.camel.util.TimeUtils; @@ -53,6 +55,12 @@ public class HttpProxyRouteTest extends BaseJettyTest { String out = template.requestBody("http://localhost:{{port}}/proxyServer", null, String.class); assertEquals("Get a wrong host header", "localhost:" + getPort2(), out); } + + @Test + public void testHttpProxyFormHeader() throws Exception { + String out = template.requestBodyAndHeader("http://localhost:{{port}}/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() { @@ -71,6 +79,19 @@ public class HttpProxyRouteTest extends BaseJettyTest { .to("http://localhost:{{port2}}/host?bridgeEndpoint=true"); from("jetty://http://localhost:{{port2}}/host").transform(header("host")); + + // check the from request + from("jetty://http://localhost:{{port}}/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); + } + + }); } }; }