Repository: camel
Updated Branches:
  refs/heads/master 41a6b93eb -> 2a54a0ab6


CAMEL-8078 camel-restlet should support to decode the response entity which is 
represent resource


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

Branch: refs/heads/master
Commit: 2a54a0ab67c9a2c58d9d778de49c4422f294eab5
Parents: 3697fbc
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Tue Nov 25 15:36:09 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Tue Nov 25 16:18:14 2014 +0800

----------------------------------------------------------------------
 .../camel/component/restlet/DefaultRestletBinding.java  |  7 ++++++-
 .../camel/component/restlet/RestletSetBodyTest.java     | 12 ++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2a54a0ab/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 8650021..bbe2acf 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
@@ -51,6 +51,8 @@ import org.restlet.data.MediaType;
 import org.restlet.data.Method;
 import org.restlet.data.Preference;
 import org.restlet.data.Status;
+import org.restlet.engine.application.DecodeRepresentation;
+import org.restlet.engine.application.EncodeRepresentation;
 import org.restlet.engine.header.Header;
 import org.restlet.engine.header.HeaderConstants;
 import org.restlet.representation.FileRepresentation;
@@ -334,8 +336,11 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
             }
             if (mediaType != null && 
mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
                 exchange.getOut().setBody(response.getEntity().getStream());
+            } else if (response.getEntity() instanceof Representation) {
+                Representation representationDecoded = new 
DecodeRepresentation(response.getEntity()); 
+                exchange.getOut().setBody(representationDecoded.getText());    
             } else {
-                // get content text
+                // get content text by default
                 String text = response.getEntity().getText();
                 LOG.debug("Populate exchange from Restlet response: {}", text);
                 exchange.getOut().setBody(text);

http://git-wip-us.apache.org/repos/asf/camel/blob/2a54a0ab/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
index 6ceb8b4..50d8901 100644
--- 
a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
+++ 
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletSetBodyTest.java
@@ -26,8 +26,11 @@ import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.junit.Test;
+import org.restlet.data.Encoding;
 import org.restlet.data.MediaType;
+import org.restlet.engine.application.EncodeRepresentation;
 import org.restlet.representation.InputRepresentation;
+import org.restlet.representation.StringRepresentation;
 
 /**
  * @version 
@@ -66,6 +69,12 @@ public class RestletSetBodyTest extends RestletTestSupport {
         }
     }
     
+    @Test
+    public void testGzipEntity() {
+        String response = template.requestBody("restlet:http://0.0.0.0:"; + 
portNum + "/gzip/data?restletMethod=get", null, String.class);
+        assertEquals("Hello World!", response);
+    }
+    
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -88,6 +97,9 @@ public class RestletSetBodyTest extends RestletTestSupport {
 
                 from("restlet:http://0.0.0.0:"; + portNum + 
"/images/{symbol}?restletMethods=get")
                     .setBody().constant(new InputRepresentation(inputStream, 
MediaType.IMAGE_PNG, 10));
+                
+                from("restlet:http://0.0.0.0:"; + portNum + 
"/gzip/data?restletMethods=get")
+                    .setBody().constant(new 
EncodeRepresentation(Encoding.GZIP, new StringRepresentation("Hello 
World!",MediaType.TEXT_XML)));
             }
         };
     }

Reply via email to