You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/03 20:04:00 UTC
[1/2] camel git commit: CAMEL-8078 camel-restlet should support to
decode the response entity which is represent resource
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 <wi...@gmail.com>
Authored: Tue Nov 25 15:36:09 2014 +0800
Committer: Claus Ibsen <da...@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)));
}
};
}
[2/2] camel git commit: CAMEL-8078 Fixed the CS error of camel-restlet
Posted by da...@apache.org.
CAMEL-8078 Fixed the CS error of camel-restlet
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f6dd8127
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f6dd8127
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f6dd8127
Branch: refs/heads/camel-2.14.x
Commit: f6dd8127835304d598e20a2a957e7f50c9993303
Parents: fbdc777
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Nov 27 15:12:01 2014 +0800
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 20:03:49 2014 +0100
----------------------------------------------------------------------
.../org/apache/camel/component/restlet/RestletSetBodyTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f6dd8127/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 50d8901..f50b4cd 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
@@ -99,7 +99,7 @@ public class RestletSetBodyTest extends RestletTestSupport {
.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)));
+ .setBody().constant(new EncodeRepresentation(Encoding.GZIP, new StringRepresentation("Hello World!", MediaType.TEXT_XML)));
}
};
}