You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/05/09 11:07:17 UTC
[2/6] git commit: CAMEL-7426 camel-http endpoint should skip reading
the form body if it is bridgeEndpoint
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/55d90fa4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/55d90fa4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/55d90fa4
Branch: refs/heads/camel-2.13.x
Commit: 55d90fa497ae38bb210018579b391e2874c8ec68
Parents: 758db04
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri May 9 16:38:30 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri May 9 16:56:38 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/55d90fa4/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 f9f3fe3..f8c6a90 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -179,6 +179,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/55d90fa4/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/55d90fa4/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/55d90fa4/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/55d90fa4/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 6dc0581..7e48d2e 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
@@ -103,6 +103,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/55d90fa4/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);
+ }
+
+ });
}
};
}