[camel] branch master updated: CAMEL-14155: xpath throws NPE if body is null when saxon is used as JAXP implementation (#3335)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-14155: xpath throws NPE if body is null when saxon is used as JAXP implementation (#3335)

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c26176  CAMEL-14155: xpath throws NPE if body is null when saxon is used as JAXP implementation (#3335)
8c26176 is described below

commit 8c2617656e9bd44b3987cb6b91feb67bb56958df
Author: Luigi De Masi <[hidden email]>
AuthorDate: Wed Nov 13 22:01:58 2019 +0100

    CAMEL-14155: xpath throws NPE if body is null when saxon is used as JAXP implementation (#3335)
---
 .../java/org/apache/camel/language/xpath/XPathBuilder.java | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java
index 27cc0b3..24b7c44 100644
--- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java
+++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathBuilder.java
@@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.xpath.XPath;
@@ -39,11 +40,9 @@ import javax.xml.xpath.XPathFactoryConfigurationException;
 import javax.xml.xpath.XPathFunction;
 import javax.xml.xpath.XPathFunctionException;
 import javax.xml.xpath.XPathFunctionResolver;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-
 import org.xml.sax.InputSource;
 
 import org.apache.camel.CamelContext;
@@ -62,10 +61,12 @@ import org.apache.camel.support.DefaultExchange;
 import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.support.MessageHelper;
 import org.apache.camel.support.builder.Namespaces;
+import org.apache.camel.support.builder.xml.XMLConverterHelper;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1030,6 +1031,9 @@ public class XPathBuilder extends ServiceSupport implements CamelContextAware, E
             }
 
             if (resultQName != null) {
+                if (document == null) {
+                    document = new XMLConverterHelper().createDocument();
+                }
                 if (document instanceof InputSource) {
                     InputSource inputSource = (InputSource)document;
                     answer = xpathExpression.evaluate(inputSource, resultQName);
@@ -1050,6 +1054,12 @@ public class XPathBuilder extends ServiceSupport implements CamelContextAware, E
                     answer = xpathExpression.evaluate(document);
                 }
             }
+        } catch (ParserConfigurationException e) {
+            String message = getText();
+            if (ObjectHelper.isNotEmpty(getHeaderName())) {
+                message = message + " with headerName " + getHeaderName();
+            }
+            throw new RuntimeCamelException(message, e);
         } catch (XPathExpressionException e) {
             String message = getText();
             if (ObjectHelper.isNotEmpty(getHeaderName())) {