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:34:40 UTC

[2/2] camel git commit: [CAMEL-11564]avoid ClassCastException when the gzip is enabled for the cxf endpoint with camel destination

[CAMEL-11564]avoid ClassCastException when the gzip is enabled for the cxf endpoint with camel destination

(cherry picked from commit d154650b293b8158de8cb7a19c4fcbc25ba67130)
(cherry picked from commit 3a738454069a1bdbeb02df2a55aa6855a48296e2)
(cherry picked from commit d4d985294a610750e60d804dcedd3a81083ba055)


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

Branch: refs/heads/camel-2.17.x
Commit: ac9208a19e262ed37ab3fc7eff8be30b17d3f288
Parents: 51b340a
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:34:26 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/ac9208a1/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 ad02956..2d38c18 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/ac9208a1/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/ac9208a1/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;
+        
+    }
 
 }