camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9833: Add mapHttpMessage option to allow to turn off mapping by default
Date Sat, 09 Apr 2016 12:40:35 GMT
Repository: camel
Updated Branches:
  refs/heads/master 342c21829 -> 0267bc898


CAMEL-9833: Add mapHttpMessage option to allow to turn off mapping by default


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b6494133
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b6494133
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b6494133

Branch: refs/heads/master
Commit: b6494133693556c95f57ccc81e8c3aa5f111fe3e
Parents: 342c218
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Apr 9 14:29:40 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Apr 9 14:29:40 2016 +0200

----------------------------------------------------------------------
 .../camel/http/common/DefaultHttpBinding.java   | 63 +++++++++++++-------
 1 file changed, 40 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b6494133/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index adf5ad1..6ded1ef 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -219,32 +219,49 @@ 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)
-                && !skipWwwFormUrlEncoding) {
-            String charset = request.getCharacterEncoding();
-            if (charset == null) {
-                charset = "UTF-8";
-            }
-            // Push POST form params into the headers to retain compatibility with DefaultHttpBinding
-            String body = message.getBody(String.class);
-            if (ObjectHelper.isNotEmpty(body)) {
-                for (String param : body.split("&")) {
-                    String[] pair = param.split("=", 2);
-                    if (pair.length == 2) {
-                        String name = URLDecoder.decode(pair[0], charset);
-                        String value = URLDecoder.decode(pair[1], charset);
-                        if (headerFilterStrategy != null
-                                && !headerFilterStrategy.applyFilterToExternalHeaders(name,
value, message.getExchange())) {
-                            HttpHelper.appendHeader(headers, name, value);
+        // should we extract key=value pairs from form bodies (application/x-www-form-urlencoded)
+        // and map those to Camel headers
+        if (mapHttpMessageBody && mapHttpMessageHeaders) {
+            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)
+                    && !skipWwwFormUrlEncoding) {
+                String charset = request.getCharacterEncoding();
+                if (charset == null) {
+                    charset = "UTF-8";
+                }
+
+                // lets parse the body
+                Object body = message.getBody();
+                // reset the stream cache if the body is the instance of StreamCache
+                if (body instanceof StreamCache) {
+                    ((StreamCache) body).reset();
+                }
+
+                // Push POST form params into the headers to retain compatibility with DefaultHttpBinding
+                String text = message.getBody(String.class);
+                if (ObjectHelper.isNotEmpty(text)) {
+                    for (String param : text.split("&")) {
+                        String[] pair = param.split("=", 2);
+                        if (pair.length == 2) {
+                            String name = URLDecoder.decode(pair[0], charset);
+                            String value = URLDecoder.decode(pair[1], charset);
+                            if (headerFilterStrategy != null
+                                    && !headerFilterStrategy.applyFilterToExternalHeaders(name,
value, message.getExchange())) {
+                                HttpHelper.appendHeader(headers, name, value);
+                            }
+                        } else {
+                            throw new IllegalArgumentException("Invalid parameter, expected
to be a pair but was " + param);
                         }
-                    } else {
-                        throw new IllegalArgumentException("Invalid parameter, expected to
be a pair but was " + param);
                     }
                 }
+
+                // reset the stream cache if the body is the instance of StreamCache
+                if (body instanceof StreamCache) {
+                    ((StreamCache) body).reset();
+                }
             }
         }
     }


Mime
View raw message