Author: ningjiang
Date: Sat Apr  5 00:30:44 2008
New Revision: 645038

URL: http://svn.apache.org/viewvc?rev=645038&view=rev
Log:
CAMLE-439 patch applied with thanks to Art

Modified:
    
activemq/camel/trunk/components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java
    
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/BeanWithJXPathInjectionTest.java
    
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java

Modified: 
activemq/camel/trunk/components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java?rev=645038&r1=645037&r2=645038&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jxpath/src/main/java/org/apache/camel/language/jxpath/JXPathExpression.java
 Sat Apr  5 00:30:44 2008
@@ -30,55 +30,55 @@
  */
 public class JXPathExpression extends ExpressionSupport<Exchange> {
 
-       private String expression;
-       private CompiledExpression compiledExpression;
-       private final Class<?> type;
-
-       /**
-        * Creates a new JXPathExpression instance
-        * 
-        * @param expression the JXPath expression to be evaluated
-        * @param type the expected result type
-        */
-       public JXPathExpression(String expression, Class<?> type) {
-               super();
-               this.expression = expression;
-               this.type = type;
-       }
+    private String expression;
+    private CompiledExpression compiledExpression;
+    private final Class<?> type;
+
+    /**
+     * Creates a new JXPathExpression instance
+     * 
+     * @param expression the JXPath expression to be evaluated
+     * @param type the expected result type
+     */
+    public JXPathExpression(String expression, Class<?> type) {
+        super();
+        this.expression = expression;
+        this.type = type;
+    }
+
 
-    
     public Object evaluate(Exchange exchange) {
-               try {
+        try {
             JXPathContext context = JXPathContext.newContext(exchange);
             Object result = getJXPathExpression().getValue(context, type);
-                       assertResultType(exchange, result);
-                       return result;
-               } catch (JXPathException e) {
-                       throw new ExpressionEvaluationException(this, exchange, 
e);
-               }
-       }
-
-       /*
-        * Check if the result is of the specified type
-        */
-       private void assertResultType(Exchange exchange, Object result) {
-               if (!type.isAssignableFrom(result.getClass())) {
-                       throw new JXPathException("JXPath result type is " + 
result.getClass() + " instead of required type " + type);
-               }
-       }
-
-       @Override
-       protected String assertionFailureMessage(Exchange exchange) {
-               return expression.toString();
-       }
-       
-       /*
-        * Get a compiled expression instance for better performance
-        */
-       private synchronized CompiledExpression getJXPathExpression() {
-               if (compiledExpression == null) {
-                       compiledExpression = JXPathContext.compile(expression);
-               }
-               return compiledExpression;
-       }
+            assertResultType(exchange, result);
+            return result;
+        } catch (JXPathException e) {
+            throw new ExpressionEvaluationException(this, exchange, e);
+        }
+    }
+
+    /*
+     * Check if the result is of the specified type
+     */
+    private void assertResultType(Exchange exchange, Object result) {
+        if (result != null && !type.isAssignableFrom(result.getClass())) {
+            throw new JXPathException("JXPath result type is " + 
result.getClass() + " instead of required type " + type);
+        }
+    }
+
+    @Override
+    protected String assertionFailureMessage(Exchange exchange) {
+        return expression.toString();
+    }
+
+    /*
+     * Get a compiled expression instance for better performance
+     */
+    private synchronized CompiledExpression getJXPathExpression() {
+        if (compiledExpression == null) {
+            compiledExpression = JXPathContext.compile(expression);
+        }
+        return compiledExpression;
+    }
 }

Modified: 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/BeanWithJXPathInjectionTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/BeanWithJXPathInjectionTest.java?rev=645038&r1=645037&r2=645038&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/BeanWithJXPathInjectionTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/BeanWithJXPathInjectionTest.java
 Sat Apr  5 00:30:44 2008
@@ -40,6 +40,13 @@
         assertEquals("bean foo: " + myBean, "James", myBean.name);
         assertNotNull("Should pass body as well", myBean.body);
     }
+    
+    public void testSendNullMessage() throws Exception {
+        template.sendBody("direct:in", new PersonBean(null, "London"));
+
+        assertEquals("bean foo: " + myBean, null, myBean.name);
+        assertNotNull("Should pass body as well", myBean.body);        
+    }
 
     @Override
     protected Context createJndiContext() throws Exception {
@@ -71,4 +78,4 @@
             LOG.info("read() method called on " + this);
         }
     }
-}
\ No newline at end of file
+}

Modified: 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java?rev=645038&r1=645037&r2=645038&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java
 Sat Apr  5 00:30:44 2008
@@ -39,6 +39,14 @@
 
         assertMockEndpointsSatisifed();
     }
+    
+    public void testSendNullMessage() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        sendBody("direct:start", new PersonBean(null, "Tampa"));
+
+        assertMockEndpointsSatisifed();
+    }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -51,4 +59,4 @@
             }
         };
     }
-}
\ No newline at end of file
+}


Reply via email to