Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed native issue and completed test/documentation #1710 #2585

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 29 additions & 5 deletions docs/modules/ROOT/pages/reference/extensions/saxon.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
= XQuery
:linkattrs:
:cq-artifact-id: camel-quarkus-saxon
:cq-native-supported: false
:cq-status: Preview
:cq-status-deprecation: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Query and/or transform XML payloads using XQuery and Saxon.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.9.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.9.0##

Query and/or transform XML payloads using XQuery and Saxon.

Expand All @@ -25,6 +25,10 @@ Please refer to the above links for usage and configuration details.

== Maven coordinates

https://code.quarkus.io/?extension-search=camel-quarkus-saxon[Create a new project with this extension on code.quarkus.io, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
Expand All @@ -34,3 +38,23 @@ Please refer to the above links for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

Beyond standard usages described above, a trick is needed when using the xquery language and component with classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the 2 routes below would load a xquery script from 2 classpath resources respectively named _myxquery.txt_ and _another-xquery.txt_:
[source,java]
----
from("direct:start").transform().xquery("resource:classpath:myxquery.txt", String.class);
from("direct:start").to("xquery:another-xquery.txt");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = *.txt
----

More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].

6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/components/xquery.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-saxon
:cq-artifact-id-base: saxon
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.9.0
:cq-camel-part-name: xquery
:cq-camel-part-title: XQuery
:cq-camel-part-description: Query and/or transform XML payloads using XQuery and Saxon.
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/languages/xquery.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-saxon
:cq-artifact-id-base: saxon
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.9.0
:cq-camel-part-name: xquery
:cq-camel-part-title: XQuery
:cq-camel-part-description: Evaluate an XQuery expressions against an XML payload.
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
<module>redis</module>
<module>ribbon</module>
<module>robotframework</module>
<module>saxon</module>
<module>schematron</module>
<module>sip</module>
<module>smpp</module>
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<module>saga</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>saxon</module>
<module>scheduler</module>
<module>seda</module>
<module>servicenow</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.saxon.deployment;

import java.util.Collection;

import org.w3c.dom.Document;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import net.sf.saxon.functions.SystemFunction;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

class SaxonProcessor {

private static final Logger LOG = Logger.getLogger(SaxonProcessor.class);
private static final String FEATURE = "camel-saxon";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void registerReflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
CombinedIndexBuildItem index) {

// Needed to register default object models when initializing the net.sf.saxon.java.JavaPlatform
reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false, Document.class));

// Register saxon functions as reflective
Collection<ClassInfo> cis = index.getIndex()
.getAllKnownSubclasses(DotName.createSimple(SystemFunction.class.getName()));
cis.stream().forEach(ci -> {
String clazzName = ci.asClass().name().toString();
ReflectiveClassBuildItem clazz = new ReflectiveClassBuildItem(false, false, clazzName);
LOG.debugf("Registering saxon function '%s' as reflective", clazzName);
reflectiveClasses.produce(clazz);
});
}

@BuildStep
void indexSaxonHe(BuildProducer<IndexDependencyBuildItem> deps) {
deps.produce(new IndexDependencyBuildItem("net.sf.saxon", "Saxon-HE"));
}
}
1 change: 0 additions & 1 deletion extensions-jvm/saxon/pom.xml → extensions/saxon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.9.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand Down
16 changes: 16 additions & 0 deletions extensions/saxon/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Beyond standard usages described above, a trick is needed when using the xquery language and component with classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the 2 routes below would load a xquery script from 2 classpath resources respectively named _myxquery.txt_ and _another-xquery.txt_:
[source,java]
----
from("direct:start").transform().xquery("resource:classpath:myxquery.txt", String.class);
from("direct:start").to("xquery:another-xquery.txt");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = *.txt
----

More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel XQuery"
description: "Query and/or transform XML payloads using XQuery and Saxon"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/saxon.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<module>saga</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>saxon</module>
<module>servicenow</module>
<module>servlet</module>
<module>shiro</module>
Expand Down