camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r676641 - /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
Date Mon, 14 Jul 2008 16:50:28 GMT
Author: jstrachan
Date: Mon Jul 14 09:50:27 2008
New Revision: 676641

URL: http://svn.apache.org/viewvc?rev=676641&view=rev
Log:
avoid NullPointerException if no CamelContext set on an Exchange

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.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=676641&r1=676640&r2=676641&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
Mon Jul 14 09:50:27 2008
@@ -19,6 +19,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.CamelContext;
 import org.apache.camel.util.UuidGenerator;
 
 /**
@@ -52,16 +53,19 @@
     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, 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
-                // from the Message itself as its got efficient implementations of them,
before trying the
-                // payload
-                answer = converter.convertTo(type, this);
+            CamelContext camelContext = e.getContext();
+            if (camelContext != null) {
+                TypeConverter converter = camelContext.getTypeConverter();
+                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
+                    // from the Message itself as its got efficient implementations of them,
before trying the
+                    // payload
+                    answer = converter.convertTo(type, this);
+                }
+                return answer;
             }
-            return answer;
         }
         return (T)getBody();
     }



Mime
View raw message