camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1372249 - in /camel/branches/camel-2.10.x: ./ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/ components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ components/camel-cxf/src/test/java/org/apache/cam...
Date Mon, 13 Aug 2012 03:11:52 GMT
Author: ningjiang
Date: Mon Aug 13 03:11:52 2012
New Revision: 1372249

URL: http://svn.apache.org/viewvc?rev=1372249&view=rev
Log:
 CAMEL-5499 Fixed the Cxf fallback converter issue of return null instead of Void.value

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerProviderTest.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/ConverterTest.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1371967,1372244-1372245

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java?rev=1372249&r1=1372248&r2=1372249&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
Mon Aug 13 03:11:52 2012
@@ -142,7 +142,8 @@ public final class CxfConverter {
         // CXF-WS MessageContentsList class
         if (MessageContentsList.class.isAssignableFrom(value.getClass())) {
             MessageContentsList list = (MessageContentsList)value;
-
+            
+            // try to turn the first array element into the object that we want
             for (Object embedded : list) {
                 if (embedded != null) {
                     if (type.isInstance(embedded)) {
@@ -150,7 +151,12 @@ public final class CxfConverter {
                     } else {
                         TypeConverter tc = registry.lookup(type, embedded.getClass());
                         if (tc != null) {
-                            return tc.convertTo(type, exchange, embedded);
+                            Object result = tc.convertTo(type, exchange, embedded);
+                            if (result != null) {
+                                return (T)result;
+                            }
+                            // there is no suitable result will be return
+                            break;
                         }
                     }
                 }

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java?rev=1372249&r1=1372248&r2=1372249&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
Mon Aug 13 03:11:52 2012
@@ -169,8 +169,15 @@ public final class CxfPayloadConverter {
                 }                
             }
             TypeConverter tc = registry.lookup(type, NodeList.class);
-            if (tc != null) {
-                return tc.convertTo(type, cxfPayloadToNodeList((CxfPayload<?>) value,
exchange));
+            if (tc != null) { 
+                Object result = tc.convertTo(type, cxfPayloadToNodeList((CxfPayload<?>)
value, exchange));
+                if (result == null) {
+                    // no we could not do it currently, and we just abort the convert here
+                    return (T) Void.TYPE;
+                } else {
+                    return (T) result;
+                }
+                
             }
             // we cannot convert a node list, so we try the first item from the
             // node list

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerProviderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerProviderTest.java?rev=1372249&r1=1372248&r2=1372249&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerProviderTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerProviderTest.java
Mon Aug 13 03:11:52 2012
@@ -59,7 +59,6 @@ public class CxfConsumerProviderTest ext
                 from(getFromEndpointUri()).process(new Processor() {
                     public void process(final Exchange exchange) {
                         Message in = exchange.getIn();
-                        // Get the parameter list
                         Node node = in.getBody(Node.class);
                         assertNotNull(node);
                         XmlConverter xmlConverter = new XmlConverter();
@@ -80,7 +79,7 @@ public class CxfConsumerProviderTest ext
         assertTrue("Get a wrong response ", response.startsWith(RESPONSE_MESSAGE_BEGINE));
         assertTrue("Get a wrong response ", response.endsWith(RESPONSE_MESSAGE_END));
         try {
-            response = template.requestBody(simpleEndpointAddress, null, String.class);
+            template.requestBody(simpleEndpointAddress, null, String.class);
             fail("Excpetion to get exception here");
         } catch (Exception ex) {
             // do nothing here

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/ConverterTest.java?rev=1372249&r1=1372248&r2=1372249&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/ConverterTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/ConverterTest.java
Mon Aug 13 03:11:52 2012
@@ -17,19 +17,29 @@
 package org.apache.camel.component.cxf.converter;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.ws.rs.core.Response;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.cxf.message.MessageContentsList;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 
+
 public class ConverterTest extends Assert {
     
     @Test
@@ -67,5 +77,32 @@ public class ConverterTest extends Asser
         assertTrue("We should get the inputStream here ", result instanceof ByteArrayInputStream);
         EasyMock.verify(response);
     }
+    
+    @Test
+    public void testFallbackConverter() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        Exchange exchange = new DefaultExchange(context);
+        MessageContentsList list = new MessageContentsList();
+        NodeListWrapper nl = new NodeListWrapper(new ArrayList<Element>());
+        list.add(nl);
+        exchange.getIn().setBody(list);
+        Node node = exchange.getIn().getBody(Node.class);
+        assertNull(node);
+        
+        File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+        Document document = documentBuilder.parse(file);
+        document.getDocumentElement().normalize();
+        List<Element> elements = new ArrayList<Element>();
+        elements.add(document.getDocumentElement());
+        nl = new NodeListWrapper(elements);
+        list.clear();
+        list.add(nl);
+        exchange.getIn().setBody(list);
+        node = exchange.getIn().getBody(Node.class);
+        assertNotNull(node);
+    }
 
 }



Mime
View raw message