This is an automated email from the ASF dual-hosted git repository. ppalaga 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 1976504 XML Tokenize language native support 1976504 is described below commit 19765046e64b5f39ee6b8aeaed27b3514986b2c3 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Tue Jan 26 14:09:39 2021 +0000 XML Tokenize language native support Fixes #780 --- catalog/pom.xml | 13 ++++ .../ROOT/pages/reference/extensions/xml-jaxp.adoc | 15 +++++ .../xml-jaxp/runtime/src/main/doc/usage.adoc | 11 ++++ extensions-support/pom.xml | 1 + extensions-support/{ => stax/deployment}/pom.xml | 61 +++++++++--------- .../stax/deployment/StaxSupportProcessor.java | 61 ++++++++++++++++++ extensions-support/{ => stax}/pom.xml | 32 ++-------- extensions-support/stax/runtime/pom.xml | 74 ++++++++++++++++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 28 ++++++++ integration-tests/xml/pom.xml | 34 ++++++++++ .../quarkus/component/xml/it/XmlResource.java | 22 +++++++ .../quarkus/component/xml/it/XmlRouteBuilder.java | 7 ++ .../camel/quarkus/component/xml/it/XmlTest.java | 21 ++++++ poms/bom/pom.xml | 10 +++ 14 files changed, 335 insertions(+), 55 deletions(-) diff --git a/catalog/pom.xml b/catalog/pom.xml index f9edefc..da1081a 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -3767,6 +3767,19 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-webhook</artifactId> <version>${project.version}</version> <type>pom</type> diff --git a/docs/modules/ROOT/pages/reference/extensions/xml-jaxp.adoc b/docs/modules/ROOT/pages/reference/extensions/xml-jaxp.adoc index ae0678c..290f4b2 100644 --- a/docs/modules/ROOT/pages/reference/extensions/xml-jaxp.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/xml-jaxp.adoc @@ -32,3 +32,18 @@ Please refer to the above link for usage and configuration details. ---- Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Usage + +To use the XML Tokenize language, a StAX Reader implementation must be present on the classpath. + +For convenience, Camel Quarkus provides a StAX extension with native mode support. + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> +</dependency> +---- + diff --git a/extensions-core/xml-jaxp/runtime/src/main/doc/usage.adoc b/extensions-core/xml-jaxp/runtime/src/main/doc/usage.adoc new file mode 100644 index 0000000..b49c71e --- /dev/null +++ b/extensions-core/xml-jaxp/runtime/src/main/doc/usage.adoc @@ -0,0 +1,11 @@ +To use the XML Tokenize language, a StAX Reader implementation must be present on the classpath. + +For convenience, Camel Quarkus provides a StAX extension with native mode support. + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> +</dependency> +---- diff --git a/extensions-support/pom.xml b/extensions-support/pom.xml index 53be603..40bb2d4 100644 --- a/extensions-support/pom.xml +++ b/extensions-support/pom.xml @@ -50,6 +50,7 @@ <module>reactor-netty</module> <module>retrofit</module> <module>spring</module> + <module>stax</module> <module>webhook</module> <module>xstream</module> <module>xalan</module> diff --git a/extensions-support/pom.xml b/extensions-support/stax/deployment/pom.xml similarity index 51% copy from extensions-support/pom.xml copy to extensions-support/stax/deployment/pom.xml index 53be603..93d5273 100644 --- a/extensions-support/pom.xml +++ b/extensions-support/stax/deployment/pom.xml @@ -18,40 +18,41 @@ --> <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"> - <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus</artifactId> + <artifactId>camel-quarkus-support-stax-parent</artifactId> <version>1.7.0-SNAPSHOT</version> </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-extensions-support</artifactId> - <name>Camel Quarkus :: Extensions :: Support</name> - <packaging>pom</packaging> - - <modules> - <!-- extensions a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat --> - <module>ahc</module> - <module>aws</module> - <module>aws2</module> - <module>bouncycastle</module> - <module>common</module> - <module>commons-logging</module> - <module>consul-client</module> - <module>debezium</module> - <module>google-http-client</module> - <module>httpclient</module> - <module>jackson-dataformat-xml</module> - <module>jetty</module> - <module>mail</module> - <module>mongodb</module> - <module>reactor-netty</module> - <module>retrofit</module> - <module>spring</module> - <module>webhook</module> - <module>xstream</module> - <module>xalan</module> - </modules> + <artifactId>camel-quarkus-support-stax-deployment</artifactId> + <name>Camel Quarkus :: Support :: StAX :: Deployment</name> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <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-support/stax/deployment/src/main/java/org/apache/camel/quarkus/support/stax/deployment/StaxSupportProcessor.java b/extensions-support/stax/deployment/src/main/java/org/apache/camel/quarkus/support/stax/deployment/StaxSupportProcessor.java new file mode 100644 index 0000000..34ee5c0 --- /dev/null +++ b/extensions-support/stax/deployment/src/main/java/org/apache/camel/quarkus/support/stax/deployment/StaxSupportProcessor.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.quarkus.support.stax.deployment; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Set; +import java.util.stream.Stream; + +import javax.xml.stream.XMLEventFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; +import io.quarkus.deployment.util.ServiceUtil; +import org.codehaus.stax2.validation.XMLValidationSchemaFactory; + +import static io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem.SPI_ROOT; + +public class StaxSupportProcessor { + + @BuildStep + void registerServices(BuildProducer<ServiceProviderBuildItem> serviceProvider) { + Stream.concat( + Stream.of( + XMLEventFactory.class, + XMLInputFactory.class, + XMLOutputFactory.class) + .map(Class::getName), + Stream.of( + XMLValidationSchemaFactory.INTERNAL_ID_SCHEMA_DTD, + XMLValidationSchemaFactory.INTERNAL_ID_SCHEMA_RELAXNG, + XMLValidationSchemaFactory.INTERNAL_ID_SCHEMA_W3C) + .map(schemaId -> XMLValidationSchemaFactory.class.getName() + "." + schemaId)) + .forEach(serviceName -> { + try { + final Set<String> names = ServiceUtil.classNamesNamedIn(Thread.currentThread().getContextClassLoader(), + SPI_ROOT + serviceName); + serviceProvider.produce(new ServiceProviderBuildItem(serviceName, new ArrayList<>(names))); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } +} diff --git a/extensions-support/pom.xml b/extensions-support/stax/pom.xml similarity index 56% copy from extensions-support/pom.xml copy to extensions-support/stax/pom.xml index 53be603..6c1cf52 100644 --- a/extensions-support/pom.xml +++ b/extensions-support/stax/pom.xml @@ -21,37 +21,19 @@ <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus</artifactId> + <artifactId>camel-quarkus-build-parent</artifactId> <version>1.7.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> - <artifactId>camel-quarkus-extensions-support</artifactId> - <name>Camel Quarkus :: Extensions :: Support</name> + <artifactId>camel-quarkus-support-stax-parent</artifactId> + <name>Camel Quarkus :: Support :: StAX</name> <packaging>pom</packaging> - <modules> - <!-- extensions a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat --> - <module>ahc</module> - <module>aws</module> - <module>aws2</module> - <module>bouncycastle</module> - <module>common</module> - <module>commons-logging</module> - <module>consul-client</module> - <module>debezium</module> - <module>google-http-client</module> - <module>httpclient</module> - <module>jackson-dataformat-xml</module> - <module>jetty</module> - <module>mail</module> - <module>mongodb</module> - <module>reactor-netty</module> - <module>retrofit</module> - <module>spring</module> - <module>webhook</module> - <module>xstream</module> - <module>xalan</module> + <module>deployment</module> + <module>runtime</module> </modules> + </project> diff --git a/extensions-support/stax/runtime/pom.xml b/extensions-support/stax/runtime/pom.xml new file mode 100644 index 0000000..dc261b7 --- /dev/null +++ b/extensions-support/stax/runtime/pom.xml @@ -0,0 +1,74 @@ +<?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"> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax-parent</artifactId> + <version>1.7.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-quarkus-support-stax</artifactId> + <name>Camel Quarkus :: Support :: StAX :: Runtime</name> + + <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>io.quarkus</groupId> + <artifactId>quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.woodstox</groupId> + <artifactId>woodstox-core</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <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-support/stax/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions-support/stax/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..988c203 --- /dev/null +++ b/extensions-support/stax/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,28 @@ +# +# 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 Support StAX" +description: "Camel Quarkus Support StAX" +metadata: + unlisted: true + keywords: + - "camel" + - "StAX" + 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 eec720b..676277c 100644 --- a/integration-tests/xml/pom.xml +++ b/integration-tests/xml/pom.xml @@ -47,6 +47,14 @@ <artifactId>camel-quarkus-direct</artifactId> </dependency> <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-seda</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> + </dependency> + <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> @@ -79,6 +87,32 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-seda-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-tagsoup-deployment</artifactId> <version>${project.version}</version> <type>pom</type> 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 8d1ebf4..fd1e2f4 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 @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.component.xml.it; +import java.util.StringJoiner; + import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.Consumes; @@ -24,6 +26,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.apache.camel.ConsumerTemplate; import org.apache.camel.ProducerTemplate; import org.jboss.logging.Logger; @@ -36,6 +39,9 @@ public class XmlResource { @Inject ProducerTemplate producerTemplate; + @Inject + ConsumerTemplate consumerTemplate; + @Path("/html-parse") @POST @Consumes(MediaType.TEXT_HTML) @@ -86,4 +92,20 @@ public class XmlResource { public String xpath(String message) { return producerTemplate.requestBody(XmlRouteBuilder.DIRECT_XML_CBR, message, String.class); } + + @Path("/xtokenize") + @POST + @Consumes(MediaType.APPLICATION_XML) + @Produces(MediaType.TEXT_PLAIN) + public String tokenize(String message) { + producerTemplate.sendBody(XmlRouteBuilder.DIRECT_XTOKENIZE, message); + + StringJoiner joiner = new StringJoiner(","); + String tokenizedXML; + while ((tokenizedXML = consumerTemplate.receiveBody("seda:xtokenize-result", 500, String.class)) != null) { + joiner.add(tokenizedXML); + } + return joiner.toString(); + } + } 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 f19c3fb..4b678f5 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 @@ -20,12 +20,14 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.support.builder.Namespaces; 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"; + public static final String DIRECT_XTOKENIZE = "direct:xtokenize"; @Override public void configure() { @@ -70,5 +72,10 @@ public class XmlRouteBuilder extends RouteBuilder { .setBody(constant("Country UK")) .otherwise() .setBody(constant("Invalid country code")); + + from(DIRECT_XTOKENIZE) + .split() + .xtokenize("//C:child", new Namespaces("C", "urn:c")) + .to("seda:xtokenize-result"); } } 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 a2c0000..cce580b 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 @@ -116,4 +116,25 @@ class XmlTest { .statusCode(200) .body(is("Invalid country code")); } + + @Test + public void xtokenizeLanguage() { + String expectedResult = "<c:child some_attr='a' anotherAttr='a' xmlns:c=\"urn:c\"></c:child>,<c:child some_attr='b' anotherAttr='b' xmlns:c=\"urn:c\"></c:child>"; + String xml = "<?xml version='1.0' encoding='UTF-8'?>" + + "<c:parent xmlns:c='urn:c'>" + + "<c:child some_attr='a' anotherAttr='a'>" + + "</c:child>" + + "<c:child some_attr='b' anotherAttr='b'>" + + "</c:child>" + + "</c:parent>"; + + // Tests a simple xpath driven content based router + RestAssured.given() + .contentType(ContentType.XML) + .body(xml) + .post("/xml/xtokenize") + .then() + .statusCode(200) + .body(is(expectedResult)); + } } diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 0c16870..c0b92b8 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -4989,6 +4989,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-stax-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-support-webhook</artifactId> <version>${camel-quarkus.version}</version> </dependency>