camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject [1/2] camel git commit: [CAMEL-11564]avoid ClassCastException when the gzip is enabled for the cxf endpoint with camel destination
Date Thu, 20 Jul 2017 03:34:39 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 51b340a5b -> ac9208a19
  refs/heads/camel-2.18.x 4c2840eaf -> d4d985294


[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)


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

Branch: refs/heads/camel-2.18.x
Commit: d4d985294a610750e60d804dcedd3a81083ba055
Parents: 4c2840e
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Thu Jul 20 11:30:44 2017 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Thu Jul 20 11:33:52 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/d4d98529/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/d4d98529/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/d4d98529/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;
+        
+    }
 
 }


Mime
View raw message