Author: ningjiang
Date: Thu May 26 13:05:11 2011
New Revision: 1127894

URL: http://svn.apache.org/viewvc?rev=1127894&view=rev
Log:
CAMEL-4016 CXF producer should not store the attachement into the out 
(response) message in POJO data format

Added:
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
   (with props)
    
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
   (with props)
Modified:
    
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java

Modified: 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java?rev=1127894&r1=1127893&r2=1127894&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
 Thu May 26 13:05:11 2011
@@ -155,10 +155,10 @@ public class DefaultCxfBinding implement
         
         // propagate protocol headers
         propagateHeadersFromCxfToCamel(cxfMessage, camelExchange.getOut(), 
camelExchange);
-        
-        if (cxfMessage.getAttachments() != null) {
-            cxfMessage.getAttachments().size();
-           
+        DataFormat dataFormat = 
camelExchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY,  
+                                                          DataFormat.class);
+        // propagate attachments if the data format is not POJO   
+        if (cxfMessage.getAttachments() != null && 
!DataFormat.POJO.equals(dataFormat)) {
             // propagate attachments
             for (Attachment attachment : cxfMessage.getAttachments()) {
                 camelExchange.getOut().addAttachment(attachment.getId(), 
attachment.getDataHandler());

Added: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java?rev=1127894&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
 Thu May 26 13:05:11 2011
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Holder;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.Assert;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.cxf.mtom_feature.Hello;
+import org.apache.camel.cxf.mtom_feature.HelloService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import 
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Unit test for exercising MTOM enabled end-to-end router in PAYLOAD mode
+ * 
+ * @version 
+ */
+@ContextConfiguration
+public class CxfMtomPOJOProducerTest extends AbstractJUnit4SpringContextTests {
+        
+    @Autowired
+    protected CamelContext context;
+    private Endpoint endpoint;
+
+    @Before
+    public void setUp() throws Exception {
+        endpoint = Endpoint.publish("http://localhost:9092/jaxws-mtom/hello";, 
getImpl());
+        SOAPBinding binding = (SOAPBinding)endpoint.getBinding();
+        binding.setMTOMEnabled(true);
+        
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testInvokingServiceFromCxfProducer() throws Exception {
+        if (Boolean.getBoolean("java.awt.headless") 
+            || System.getProperty("os.name").startsWith("Mac OS") && 
System.getProperty("user.name").equals("cruise")) {
+            System.out.println("Running headless. Skipping test as Images may 
not work.");
+            return;
+        }
+        
+        final Holder<byte[]> photo = new 
Holder<byte[]>(MtomTestHelper.REQ_PHOTO_DATA);
+        final Holder<Image> image = new Holder<Image>(getImage("/java.jpg"));
+        
+        Exchange exchange = 
context.createProducerTemplate().send("direct://testEndpoint", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(new Object[] {photo, image});
+                
+            }
+            
+        });
+        
+        // Make sure we don't put the attachement into out message
+        assertEquals("The attachement size should be 0 ", 0, 
exchange.getOut().getAttachments().size());
+        
+        Object[] result = exchange.getOut().getBody(Object[].class);
+        Holder<byte[]> photo1 = (Holder<byte[]>) result[1];
+        MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA,  
photo1.value);      
+        Holder<Image> image1 = (Holder<Image>) result[2];
+        Assert.assertNotNull(image1.value);
+        if (image.value instanceof BufferedImage) {
+            Assert.assertEquals(560, ((BufferedImage)image1.value).getWidth());
+            Assert.assertEquals(300, 
((BufferedImage)image1.value).getHeight());            
+        }
+        
+    }
+    
+    private Image getImage(String name) throws Exception {
+        return ImageIO.read(getClass().getResource(name));
+    }
+    
+    
+    protected Object getImpl() {
+        return new HelloImpl();
+    }
+    
+
+}

Propchange: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml?rev=1127894&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
 Thu May 26 13:05:11 2011
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+--><beans xmlns="http://www.springframework.org/schema/beans"; 
xmlns:cxf="http://camel.apache.org/schema/cxf"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="      
  http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd        
http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd        
http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd     ">
+
+   <cxf:cxfEndpoint xmlns:ns="http://apache.org/camel/cxf/mtom_feature";
+     id="serviceEndpoint"
+     serviceClass="org.apache.camel.cxf.mtom_feature.Hello"  
+     address="http://localhost:9092/jaxws-mtom/hello"; 
+     endpointName="ns:HelloPort" 
+     serviceName="ns:HelloService"
+     wsdlURL="mtom.wsdl">
+            
+        <cxf:properties>
+            <entry key="mtom-enabled" value="true"/>
+        </cxf:properties>  
+   </cxf:cxfEndpoint>
+   
+   <camelContext xmlns="http://camel.apache.org/schema/spring"; id="camel">
+    <route>
+        <from uri="direct:testEndpoint"/>
+        <to uri="cxf:bean:serviceEndpoint"/>
+    </route>
+</camelContext>
+</beans>
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomPOJOProducerTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to