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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2f0890f3b95 CAMEL-20438: camel-xslt - XPath evaluation fails with 
result type integer. (#13234)
2f0890f3b95 is described below

commit 2f0890f3b95eb6a8dd5779de0734991d18265fa4
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Feb 21 11:20:14 2024 +0100

    CAMEL-20438: camel-xslt - XPath evaluation fails with result type integer. 
(#13234)
---
 .../apache/camel/language/xpath/XPathLanguage.java | 11 +++---
 .../camel/language/XPathIntegerResultTest.java     | 43 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
 
b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
index 0bc94777575..ff34ea57260 100644
--- 
a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
+++ 
b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathLanguage.java
@@ -130,11 +130,7 @@ public class XPathLanguage extends 
SingleInputTypedLanguageSupport implements Pr
     protected void configureBuilder(XPathBuilder builder, Object[] properties, 
Expression source) {
         builder.setSource(source);
 
-        Class<?> clazz = property(Class.class, properties, 0, null);
-        if (clazz != null) {
-            builder.setResultType(clazz);
-        }
-        clazz = property(Class.class, properties, 2, documentType);
+        Class<?> clazz = property(Class.class, properties, 2, documentType);
         if (clazz != null) {
             builder.setDocumentType(clazz);
         }
@@ -176,6 +172,11 @@ public class XPathLanguage extends 
SingleInputTypedLanguageSupport implements Pr
         if (ns != null && !ns.isEmpty()) {
             builder.setNamespaces(ns);
         }
+        // must set result type last as it influence the QName in use
+        clazz = property(Class.class, properties, 0, null);
+        if (clazz != null) {
+            builder.setResultType(clazz);
+        }
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/XPathIntegerResultTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/XPathIntegerResultTest.java
new file mode 100644
index 00000000000..1cb60973291
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/XPathIntegerResultTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class XPathIntegerResultTest extends ContextTestSupport {
+
+    @Test
+    public void testXPathInteger() throws Exception {
+        Object out = template.requestBody("direct:start", 
"<hello><id>123</id></hello>");
+        assertIsInstanceOf(Integer.class, out);
+        Assertions.assertEquals(123, (Integer) out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .setBody(xpath("//hello/id", Integer.class));
+            }
+        };
+    }
+}

Reply via email to