You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/10/27 15:21:48 UTC

svn commit: r830198 - /camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java

Author: davsclaus
Date: Tue Oct 27 14:21:48 2009
New Revision: 830198

URL: http://svn.apache.org/viewvc?rev=830198&view=rev
Log:
Trying to fix unit test failing on JDK6 on Windows with xpath expressions with null bodies

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=830198&r1=830197&r2=830198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Tue Oct 27 14:21:48 2009
@@ -118,8 +118,13 @@
     }
 
     public boolean matches(Exchange exchange) {
-        Object booleanResult = evaluateAs(exchange, XPathConstants.BOOLEAN);
-        return exchange.getContext().getTypeConverter().convertTo(Boolean.class, booleanResult);
+        // only evaluate if there is some body
+        Object answer = exchange.getIn();
+        if (answer != null) {
+            answer = evaluateAs(exchange, XPathConstants.BOOLEAN);
+        }
+
+        return exchange.getContext().getTypeConverter().convertTo(Boolean.class, answer);
     }
 
     public <T> T evaluate(Exchange exchange, Class<T> type) {
@@ -430,10 +435,18 @@
     // -------------------------------------------------------------------------
 
     protected Object evaluate(Exchange exchange) {
-        Object answer = evaluateAs(exchange, resultQName);
+        // only evaluate if there is some body
+        Object answer = exchange.getIn();
+        if (answer != null) {
+            answer = evaluateAs(exchange, resultQName);
+        }
+
+        // let the type converter have a chance if we for example should convert to a boolean
+        // which a null body will result in false
         if (resultType != null) {
             return ExchangeHelper.convertToType(exchange, resultType, answer);
         }
+
         return answer;
     }
 
@@ -477,6 +490,14 @@
 
         try {
             Object document = getDocument(exchange);
+
+            if (document == null) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Could not evaluate XPath as Exchange cannot be converted to a Document: " + exchange + ". Returning null.");
+                }
+                return null;
+            }
+
             if (resultQName != null) {
                 if (document instanceof InputSource) {
                     InputSource inputSource = (InputSource) document;