Author: ningjiang
Date: Sun Jul 13 20:27:28 2008
New Revision: 676464

URL: http://svn.apache.org/viewvc?rev=676464&view=rev
Log:
CAMEL-709 applied patch with thanks to Claus

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=676464&r1=676463&r2=676464&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
 Sun Jul 13 20:27:28 2008
@@ -46,10 +46,14 @@
 
     @SuppressWarnings({"unchecked" })
     public <T> T getBody(Class<T> type) {
+        return getBody(type, getBody());
+    }
+
+    protected <T> T getBody(Class<T> type, Object body) {
         Exchange e = getExchange();
         if (e != null) {
             TypeConverter converter = e.getContext().getTypeConverter();
-            T answer = converter.convertTo(type, getBody());
+            T answer = converter.convertTo(type, body);
             if (answer == null) {
                 // lets first try converting the message itself first
                 // as for some types like InputStream v Reader its more 
efficient to do the transformation

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java?rev=676464&r1=676463&r2=676464&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfMessage.java
 Sun Jul 13 20:27:28 2008
@@ -21,6 +21,7 @@
 import org.apache.camel.impl.DefaultMessage;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.message.MessageContentsList;
 
 /**
  * An Apache CXF [EMAIL PROTECTED] Message} which provides access to the 
underlying CXF
@@ -115,4 +116,23 @@
             setMessage((Message) body);
         }
     }
+
+    public <T> T getBody(Class<T> type) {
+        if (!(MessageContentsList.class.isAssignableFrom(type)) && getBody() 
instanceof MessageContentsList) {
+            // if the body is the MessageContentsList then try to convert its 
payload
+            // to make it easier for end-users to use camel-cxf
+            MessageContentsList list = (MessageContentsList)getBody();
+            for (int i = 0; i < list.size(); i++) {
+                Object value = list.get(i);
+                T answer = getBody(type, value);
+                if (answer != null) {
+                    return answer;
+                }
+            }
+        }
+
+        // default to super
+        return super.getBody(type);
+    }
+
 }


Reply via email to