camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r832745 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: builder/ExpressionBuilder.java component/bean/BeanInfo.java
Date Wed, 04 Nov 2009 14:00:54 GMT
Author: davsclaus
Date: Wed Nov  4 14:00:53 2009
New Revision: 832745

URL: http://svn.apache.org/viewvc?rev=832745&view=rev
Log:
CAMEL-2133: Fixed issue with bean component in case body really was null.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=832745&r1=832744&r2=832745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Wed
Nov  4 14:00:53 2009
@@ -437,11 +437,29 @@
 
     /**
      * Returns the expression for the exchanges inbound message body converted
-     * to the given type
+     * to the given type.
+     * <p/>
+     * Does <b>not</b> allow null bodies.
      */
     public static <T> Expression mandatoryBodyExpression(final Class<T> type)
{
+        return mandatoryBodyExpression(type, false);
+    }
+
+    /**
+     * Returns the expression for the exchanges inbound message body converted
+     * to the given type
+     *
+     * @param type the type
+     * @param nullBodyAllowed whether null bodies is allowed and if so a null is returned,
+     *                        otherwise an exception is thrown
+     */
+    public static <T> Expression mandatoryBodyExpression(final Class<T> type,
final boolean nullBodyAllowed) {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
+                if (nullBodyAllowed && exchange.getIn().getBody() == null) {
+                    return null;
+                }
+
                 try {
                     return exchange.getIn().getMandatoryBody(type);
                 } catch (InvalidPayloadException e) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=832745&r1=832744&r2=832745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Wed
Nov  4 14:00:53 2009
@@ -312,8 +312,8 @@
                         expression = ExpressionBuilder.exchangeExpression();
                     } else {
                         // lets assume its the body and it must be mandatory convertable
to the parameter type
-                        // so we dont pass in null as body in case Camel cannot convert to
the parameter type
-                        expression = ExpressionBuilder.mandatoryBodyExpression(parameterType);
+                        // but we allow null bodies in case the message really contains a
null body
+                        expression = ExpressionBuilder.mandatoryBodyExpression(parameterType,
true);
                     }
                     if (LOG.isTraceEnabled()) {
                         LOG.trace("Parameter #" + i + " is the body parameter using expression
" + expression);



Mime
View raw message