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

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


The following commit(s) were added to refs/heads/master by this push:
     new c34d83e  Add xpath language extension
c34d83e is described below

commit c34d83e81524df1289ca659cc4a7955de04c78ce
Author: James Netherton <[email protected]>
AuthorDate: Fri Feb 28 08:20:13 2020 +0000

    Add xpath language extension
    
    fixes #739
---
 .../pages/list-of-camel-quarkus-extensions.adoc    |  4 +-
 extensions/pom.xml                                 |  1 +
 extensions/readme.adoc                             |  4 +-
 extensions/xpath/deployment/pom.xml                | 79 ++++++++++++++++++++
 .../component/xpath/deployment/XPathProcessor.java | 43 +++++++++++
 extensions/xpath/pom.xml                           | 39 ++++++++++
 extensions/xpath/runtime/pom.xml                   | 86 ++++++++++++++++++++++
 .../main/resources/META-INF/quarkus-extension.yaml | 27 +++++++
 integration-tests/xml/pom.xml                      |  6 +-
 .../quarkus/component/xml/it/XmlResource.java      |  7 ++
 .../quarkus/component/xml/it/XmlRouteBuilder.java  |  8 ++
 .../camel/quarkus/component/xml/it/XmlTest.java    | 19 +++++
 poms/bom-deployment/pom.xml                        |  5 ++
 poms/bom/pom.xml                                   | 10 +++
 14 files changed, 335 insertions(+), 3 deletions(-)

diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc 
b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
index 7f64403..b93d9f3 100644
--- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
+++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
@@ -273,7 +273,7 @@ Number of Camel data formats: 14 in 11 JAR artifacts (0 
deprecated)
 == Camel Languages
 
 // languages: START
-Number of Camel languages: 9 in 3 JAR artifacts (0 deprecated)
+Number of Camel languages: 10 in 4 JAR artifacts (0 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -296,6 +296,8 @@ Number of Camel languages: 9 in 3 JAR artifacts (0 
deprecated)
 | link:https://camel.apache.org/components/latest/simple-language.html[Simple] 
(camel-quarkus-core) | 0.2.0 | To use Camels built-in Simple language in Camel 
expressions or predicates.
 
 | 
link:https://camel.apache.org/components/latest/tokenize-language.html[Tokenize]
 (camel-quarkus-core) | 0.2.0 | To use Camel message body or header with a 
tokenizer in Camel expressions or predicates.
+
+| link:https://camel.apache.org/components/latest/xpath-language.html[XPath] 
(camel-quarkus-xpath) | 1.2.0 | To use XPath (XML) in Camel expressions or 
predicates.
 |===
 // languages: END
 
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 5eaf50f..9042bd3 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -115,6 +115,7 @@
         <module>twitter</module>
         <module>validator</module>
         <module>vm</module>
+        <module>xpath</module>
         <module>xslt</module>
         <module>zipfile</module>
     </modules>
diff --git a/extensions/readme.adoc b/extensions/readme.adoc
index 9e1f237..c89e3b9 100644
--- a/extensions/readme.adoc
+++ b/extensions/readme.adoc
@@ -262,7 +262,7 @@ Number of Camel data formats: 14 in 11 JAR artifacts (0 
deprecated)
 == Camel Languages
 
 // languages: START
-Number of Camel languages: 9 in 3 JAR artifacts (0 deprecated)
+Number of Camel languages: 10 in 4 JAR artifacts (0 deprecated)
 
 [width="100%",cols="4,1,5",options="header"]
 |===
@@ -285,6 +285,8 @@ Number of Camel languages: 9 in 3 JAR artifacts (0 
deprecated)
 | link:https://camel.apache.org/components/latest/simple-language.html[Simple] 
(camel-quarkus-core) | 0.2.0 | To use Camels built-in Simple language in Camel 
expressions or predicates.
 
 | 
link:https://camel.apache.org/components/latest/tokenize-language.html[Tokenize]
 (camel-quarkus-core) | 0.2.0 | To use Camel message body or header with a 
tokenizer in Camel expressions or predicates.
+
+| link:https://camel.apache.org/components/latest/xpath-language.html[XPath] 
(camel-quarkus-xpath) | 1.2.0 | To use XPath (XML) in Camel expressions or 
predicates.
 |===
 // languages: END
 
diff --git a/extensions/xpath/deployment/pom.xml 
b/extensions/xpath/deployment/pom.xml
new file mode 100644
index 0000000..631b51c
--- /dev/null
+++ b/extensions/xpath/deployment/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-xpath-parent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-xpath-deployment</artifactId>
+    <name>Camel Quarkus :: XPath :: Deployment</name>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-bom-deployment</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-core-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-support-xml-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-xpath</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            
<artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git 
a/extensions/xpath/deployment/src/main/java/org/apache/camel/quarkus/component/xpath/deployment/XPathProcessor.java
 
b/extensions/xpath/deployment/src/main/java/org/apache/camel/quarkus/component/xpath/deployment/XPathProcessor.java
new file mode 100644
index 0000000..ce0877f
--- /dev/null
+++ 
b/extensions/xpath/deployment/src/main/java/org/apache/camel/quarkus/component/xpath/deployment/XPathProcessor.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.quarkus.component.xpath.deployment;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+
+class XPathProcessor {
+
+    private static final String FEATURE = "camel-xpath";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    ReflectiveClassBuildItem registerForReflection() {
+        return new ReflectiveClassBuildItem(false, false, 
"com.sun.org.apache.xml.internal.utils.FastStringBuffer");
+    }
+
+    @BuildStep
+    SystemPropertyBuildItem xpathSystemProperties() {
+        // See https://issues.apache.org/jira/browse/XALANJ-2540
+        return new SystemPropertyBuildItem("org.apache.xml.dtm.DTMManager", 
"org.apache.xml.dtm.ref.DTMManagerDefault");
+    }
+}
diff --git a/extensions/xpath/pom.xml b/extensions/xpath/pom.xml
new file mode 100644
index 0000000..1857cbf
--- /dev/null
+++ b/extensions/xpath/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-build-parent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <relativePath>../../poms/build-parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-xpath-parent</artifactId>
+    <name>Camel Quarkus :: XPath</name>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>deployment</module>
+        <module>runtime</module>
+    </modules>
+</project>
diff --git a/extensions/xpath/runtime/pom.xml b/extensions/xpath/runtime/pom.xml
new file mode 100644
index 0000000..6375e57
--- /dev/null
+++ b/extensions/xpath/runtime/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-xpath-parent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-xpath</artifactId>
+    <name>Camel Quarkus :: XPath :: Runtime</name>
+
+    <properties>
+        <firstVersion>1.2.0</firstVersion>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-bom</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-support-xml</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-xpath</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            
<artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/extensions/xpath/runtime/src/main/resources/META-INF/quarkus-extension.yaml 
b/extensions/xpath/runtime/src/main/resources/META-INF/quarkus-extension.yaml
new file mode 100644
index 0000000..0f7c50d
--- /dev/null
+++ 
b/extensions/xpath/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+---
+name: "Camel Quarkus XPath"
+description: "Camel Quarkus XPath Support"
+metadata:
+  keywords:
+    - "camel"
+    - "xpath"
+  guide: "https://quarkus.io/guides/camel";
+  categories:
+    - "integration"
\ No newline at end of file
diff --git a/integration-tests/xml/pom.xml b/integration-tests/xml/pom.xml
index 0fb48f7..50179ef 100644
--- a/integration-tests/xml/pom.xml
+++ b/integration-tests/xml/pom.xml
@@ -36,7 +36,7 @@
         <!-- explicit dependencies of this module in the Maven sense, although 
they are required by the Quarkus Maven plugin. -->
         <!-- Please update rule whenever you change the dependencies of this 
module by running -->
         <!--     mvn process-resources -Pformat    from the root directory -->
-        
<mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-tagsoup-deployment,camel-quarkus-xslt-deployment</mvnd.builder.rule>
+        
<mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-tagsoup-deployment,camel-quarkus-xpath-deployment,camel-quarkus-xslt-deployment</mvnd.builder.rule>
     </properties>
 
     <dependencies>
@@ -50,6 +50,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-xpath</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-direct</artifactId>
         </dependency>
         <dependency>
diff --git 
a/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlResource.java
 
b/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlResource.java
index 586cd07..8d1ebf4 100644
--- 
a/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlResource.java
+++ 
b/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlResource.java
@@ -79,4 +79,11 @@ public class XmlResource {
                 String.class);
     }
 
+    @Path("/xpath")
+    @POST
+    @Consumes(MediaType.APPLICATION_XML)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String xpath(String message) {
+        return producerTemplate.requestBody(XmlRouteBuilder.DIRECT_XML_CBR, 
message, String.class);
+    }
 }
diff --git 
a/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlRouteBuilder.java
 
b/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlRouteBuilder.java
index 4ce71d4..f19c3fb 100644
--- 
a/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlRouteBuilder.java
+++ 
b/integration-tests/xml/src/main/java/org/apache/camel/quarkus/component/xml/it/XmlRouteBuilder.java
@@ -25,6 +25,7 @@ public class XmlRouteBuilder extends RouteBuilder {
     public static final String DIRECT_HTML_TO_DOM = "direct:html-to-dom";
     public static final String DIRECT_HTML_TRANSFORM = "direct:html-transfrom";
     public static final String DIRECT_HTML_TO_TEXT = "direct:html-to-text";
+    public static final String DIRECT_XML_CBR = "direct:xml-cbr";
 
     @Override
     public void configure() {
@@ -62,5 +63,12 @@ public class XmlRouteBuilder extends RouteBuilder {
                 .unmarshal().tidyMarkup()
                 // tagSoup produces DOM that is then consumed by XSLT
                 .to("xslt:xslt/html-to-text.xsl");
+
+        from(DIRECT_XML_CBR)
+                .choice()
+                .when(xpath("//order/country = 'UK'"))
+                .setBody(constant("Country UK"))
+                .otherwise()
+                .setBody(constant("Invalid country code"));
     }
 }
diff --git 
a/integration-tests/xml/src/test/java/org/apache/camel/quarkus/component/xml/it/XmlTest.java
 
b/integration-tests/xml/src/test/java/org/apache/camel/quarkus/component/xml/it/XmlTest.java
index 08861fa..8ee8a8d 100644
--- 
a/integration-tests/xml/src/test/java/org/apache/camel/quarkus/component/xml/it/XmlTest.java
+++ 
b/integration-tests/xml/src/test/java/org/apache/camel/quarkus/component/xml/it/XmlTest.java
@@ -98,4 +98,23 @@ class XmlTest {
                 actual);
     }
 
+    @Test
+    public void xpathLanguage() {
+        // Tests a simple xpath driven content based router
+        RestAssured.given()
+                .contentType(ContentType.XML)
+                
.body("<orders><order><id>1</id><country>UK</country><total>2.54</total></order></orders>")
+                .post("/xml/xpath")
+                .then()
+                .statusCode(200)
+                .body(is("Country UK"));
+
+        RestAssured.given()
+                .contentType(ContentType.XML)
+                
.body("<orders><order><id>1</id><country>FR</country><total>9.99</total></order></orders>")
+                .post("/xml/xpath")
+                .then()
+                .statusCode(200)
+                .body(is("Invalid country code"));
+    }
 }
diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml
index 493254d..575bbfc 100644
--- a/poms/bom-deployment/pom.xml
+++ b/poms/bom-deployment/pom.xml
@@ -506,6 +506,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-xpath-deployment</artifactId>
+                <version>${camel-quarkus.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
                 <artifactId>camel-quarkus-xslt-deployment</artifactId>
                 <version>${camel-quarkus.version}</version>
             </dependency>
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index 7813841..3f59e12 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -592,6 +592,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel</groupId>
+                <artifactId>camel-xpath</artifactId>
+                <version>${camel.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel</groupId>
                 <artifactId>camel-xslt</artifactId>
                 <version>${camel.version}</version>
             </dependency>
@@ -1064,6 +1069,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-xpath</artifactId>
+                <version>${camel-quarkus.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
                 <artifactId>camel-quarkus-xslt</artifactId>
                 <version>${camel-quarkus.version}</version>
             </dependency>

Reply via email to