You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2017/07/20 03:30:57 UTC
camel git commit: [CAMEL-11564]avoid ClassCastException when the gzip
is enabled for the cxf endpoint with camel destination
Repository: camel
Updated Branches:
refs/heads/master a02395e00 -> d154650b2
[CAMEL-11564]avoid ClassCastException when the gzip is enabled for the cxf endpoint with camel destination
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d154650b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d154650b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d154650b
Branch: refs/heads/master
Commit: d154650b293b8158de8cb7a19c4fcbc25ba67130
Parents: a02395e
Author: Freeman Fang <fr...@gmail.com>
Authored: Thu Jul 20 11:30:44 2017 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Thu Jul 20 11:30:44 2017 +0800
----------------------------------------------------------------------
.../component/cxf/transport/CamelDestination.java | 9 ++++++---
.../cxf/transport/JaxWSCamelDestinationTest.java | 17 +++++++++++++++++
.../cxf/transport/JaxWSCamelTestSupport.java | 14 ++++++++++++++
3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d154650b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
index 007d994..900ecbe 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
@@ -277,9 +277,12 @@ public class CamelDestination extends AbstractDestination implements Configurabl
if (checkException && exception != null) {
camelExchange.setException(exception);
}
-
- CachedOutputStream outputStream = (CachedOutputStream)outMessage.getContent(OutputStream.class);
- camelExchange.getOut().setBody(outputStream.getInputStream());
+ OutputStream outputStream = outMessage.getContent(OutputStream.class);
+ if (outputStream instanceof CachedOutputStream) {
+ camelExchange.getOut().setBody(((CachedOutputStream)outputStream).getInputStream());
+ } else {
+ camelExchange.getOut().setBody(outputStream);
+ }
LOG.debug("send the response message: {}", outputStream);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/d154650b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
index f745868..6ca7f6d 100644
--- a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
+++ b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelDestinationTest.java
@@ -21,6 +21,8 @@ import javax.xml.ws.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
+
import org.junit.After;
import org.junit.Test;
@@ -63,4 +65,19 @@ public class JaxWSCamelDestinationTest extends JaxWSCamelTestSupport {
assertTrue(exchange.getOut().getBody(String.class).indexOf("something!") > 0);
}
+ @Test
+ public void testDestinationWithGzip() {
+ // publish the endpoint
+ endpoint = publishSampleWSWithGzipEnabled("direct:endpoint");
+ Exchange exchange = template.request("direct:start", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody(REQUEST);
+ exchange.getIn().setHeader("Accept-Encoding", "gzip");
+ }
+
+ });
+ assertThat(exchange.getOut().getHeader(Exchange.CONTENT_ENCODING, String.class), is("gzip"));
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/d154650b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
index 090ee43..40acf59 100644
--- a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
+++ b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/transport/JaxWSCamelTestSupport.java
@@ -31,6 +31,7 @@ import javax.xml.ws.Service;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Before;
@@ -136,5 +137,18 @@ public class JaxWSCamelTestSupport extends CamelTestSupport {
return Endpoint.publish("camel://" + camelEndpoint, new SampleWSImpl());
}
+
+ /**
+ * Create a SampleWS Server with Gzip enabled to a specified route
+ * @param camelEndpoint
+ */
+
+ public Endpoint publishSampleWSWithGzipEnabled(String camelEndpoint) {
+ EndpointImpl endpoint = (EndpointImpl)Endpoint.publish("camel://" + camelEndpoint, new SampleWSImpl());
+ endpoint.getInInterceptors().add(new org.apache.cxf.transport.common.gzip.GZIPInInterceptor());
+ endpoint.getOutInterceptors().add(new org.apache.cxf.transport.common.gzip.GZIPOutInterceptor(0));
+ return endpoint;
+
+ }
}