Repository: camel Updated Branches: refs/heads/camel-2.14.x 543938cf0 -> f6dd81278
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/fbdc777e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fbdc777e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fbdc777e Branch: refs/heads/camel-2.14.x Commit: fbdc777e5d9041ae127d9e19e0d267374cbdef0e Parents: 543938c Author: Willem Jiang <willem.ji...@gmail.com> Authored: Tue Nov 25 15:36:09 2014 +0800 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Dec 3 20:03:38 2014 +0100 ---------------------------------------------------------------------- .../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/fbdc777e/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/fbdc777e/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))); } }; }