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 2024/03/06 09:53:32 UTC

(camel) branch xpath created (now cd7f3f35676)

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

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


      at cd7f3f35676 CAMEL-20523: camel-xpath - The resultQName converter is wrong causing CSB not to work with xpath in language endpoint

This branch includes the following new commits:

     new cd7f3f35676 CAMEL-20523: camel-xpath - The resultQName converter is wrong causing CSB not to work with xpath in language endpoint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20523: camel-xpath - The resultQName converter is wrong causing CSB not to work with xpath in language endpoint

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cd7f3f356765ac23d696bf5834a17af972f8d58b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 6 10:53:17 2024 +0100

    CAMEL-20523: camel-xpath - The resultQName converter is wrong causing CSB not to work with xpath in language endpoint
---
 .../camel/language/XPathLanguageEndpointTest.java  | 61 ++++++++++++++++++++++
 .../apache/camel/converter/jaxp/XmlConverter.java  | 12 +++++
 2 files changed, 73 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageEndpointTest.java
new file mode 100644
index 00000000000..ba1582240a1
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageEndpointTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.language;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathConstants;
+
+public class XPathLanguageEndpointTest extends ContextTestSupport {
+
+    @Test
+    public void testXPath() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "<foo>Hello World</foo>");
+
+        assertMockEndpointsSatisfied();
+
+        // test converter also works with shorthand names
+        QName qn = context.getTypeConverter().convertTo(QName.class, "NODESET");
+        Assertions.assertEquals(XPathConstants.NODESET, qn);
+        qn = context.getTypeConverter().convertTo(QName.class, "nodeset");
+        Assertions.assertEquals(XPathConstants.NODESET, qn);
+        qn = context.getTypeConverter().convertTo(QName.class, "BOOLEAN");
+        Assertions.assertEquals(XPathConstants.BOOLEAN, qn);
+        qn = context.getTypeConverter().convertTo(QName.class, "boolean");
+        Assertions.assertEquals(XPathConstants.BOOLEAN, qn);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .setHeader(Exchange.LANGUAGE_SCRIPT, constant("/foo/text()"))
+                        .to("language:xpath")
+                        .to("mock:result");
+            }
+        };
+    }
+}
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index b37dd8b523e..7fa79cffe93 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -57,6 +57,7 @@ import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -146,6 +147,17 @@ public class XmlConverter {
      */
     @Converter(order = 1)
     public QName toQName(String str) {
+        if ("NUMBER".equalsIgnoreCase(str)) {
+            return XPathConstants.NUMBER;
+        } else if ("STRING".equalsIgnoreCase(str)) {
+            return XPathConstants.STRING;
+        } else if ("BOOLEAN".equalsIgnoreCase(str)) {
+            return XPathConstants.BOOLEAN;
+        } else if ("NODESET".equalsIgnoreCase(str)) {
+            return XPathConstants.NODESET;
+        } else if ("NODE".equalsIgnoreCase(str)) {
+            return XPathConstants.NODE;
+        }
         return QName.valueOf(str);
     }