Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x dd59bf876 -> aefa04d4a
  refs/heads/master 08665fecd -> 8b3da67b8


CAMEL-9611: Restlet GET request should not trying to stringify the exchange body


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

Branch: refs/heads/master
Commit: 8b3da67b8809fbbe3ba10a125df8eefba05e82ee
Parents: 08665fe
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Feb 19 09:42:09 2016 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Feb 19 09:42:26 2016 +0100

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          | 36 ++++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8b3da67b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
 
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 69821b2..59cb219 100644
--- 
a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ 
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -150,17 +150,21 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
 
     public void populateRestletRequestFromExchange(Request request, Exchange 
exchange) {
         request.setReferrerRef("camel-restlet");
-        String body = exchange.getIn().getBody(String.class);
-        Form form = new Form();
-        // add the body as the key in the form with null value
-        form.add(body, null);
+
+        final Method method = request.getMethod();
 
         MediaType mediaType = 
exchange.getIn().getHeader(Exchange.CONTENT_TYPE, MediaType.class);
         if (mediaType == null) {
             mediaType = MediaType.APPLICATION_WWW_FORM;
         }
 
-        LOG.debug("Populate Restlet request from exchange body: {} using media 
type {}", body, mediaType);
+        Form form = null;
+        // Use forms only for PUT, POST and x-www-form-urlencoded
+        if ((Method.PUT == method || Method.POST == method) && mediaType == 
MediaType.APPLICATION_WWW_FORM) {
+            form = new Form();
+            String body = exchange.getIn().getBody(String.class);
+            form.add(body, null);
+        }
 
         // login and password are filtered by header filter strategy
         String login = 
exchange.getIn().getHeader(RestletConstants.RESTLET_LOGIN, String.class);
@@ -176,8 +180,8 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
             String key = entry.getKey();
             Object value = entry.getValue();
             if (!headerFilterStrategy.applyFilterToCamelHeaders(key, value, 
exchange)) {
-                // Use forms only for GET and POST/x-www-form-urlencoded
-                if (request.getMethod() == Method.GET || (request.getMethod() 
== Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
+                // Use forms only for PUT, POST and x-www-form-urlencoded
+                if (form != null) {
                     if (key.startsWith("org.restlet.")) {
                         // put the org.restlet headers in attributes
                         request.getAttributes().put(key, value);
@@ -199,16 +203,19 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
             }
         }
 
-        LOG.debug("Using Content Type: {} for POST data: {}", mediaType, body);
-
-        // Only URL Encode for GET and form POST
-        if (request.getMethod() == Method.GET || (request.getMethod() == 
Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
+        if (form != null) {
             request.setEntity(form.getWebRepresentation());
+            LOG.debug("Populate Restlet {} request from exchange body as form 
using media type {}", method, mediaType);
         } else {
-            if (body == null) {
-                request.setEntity(null);
-            } else {
+            // include body if PUT or POST
+            if (request.getMethod() == Method.PUT || request.getMethod() == 
Method.POST) {
+                String body = exchange.getIn().getBody(String.class);
                 request.setEntity(body, mediaType);
+                LOG.debug("Populate Restlet {} request from exchange body: {} 
using media type {}", method, body, mediaType);
+            } else {
+                // no body
+                LOG.debug("Populate Restlet {} request from exchange using 
media type {}", method, mediaType);
+                request.setEntity(null);
             }
         }
 
@@ -224,6 +231,7 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
         if (acceptedMediaType != null) {
             request.getClientInfo().getAcceptedMediaTypes().add(new 
Preference<MediaType>(acceptedMediaType));
         }
+
     }
 
     public void populateRestletResponseFromExchange(Exchange exchange, 
Response response) throws Exception {

Reply via email to