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-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 22aae8a77 Fix #3330: new xslt-action and xml-schema-validator-action
Kamelets (#3336)
22aae8a77 is described below
commit 22aae8a77b53f0e486a2f46e1ba177c6601017d9
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 02:07:39 2026 +0100
Fix #3330: new xslt-action and xml-schema-validator-action Kamelets (#3336)
* Fix #3330: new xslt-action and xml-schema-validator-action Kamelets
xslt-action transforms the XML body with an XSLT stylesheet loaded from the
template location, with the
xslt-saxon component (XSLT 3.0). A header with the name of a stylesheet
parameter sets it; headers that start
with CamelXslt are removed first. xml-schema-validator-action checks the
XML body against an XML Schema with
the validator component, passes it on unchanged when valid and fails the
message with the list of errors
when not.
The XmlIT Citrus tests check a transformation with a parameter, String and
bytes bodies, document() from the
classpath, a valid and an invalid document, a body that is not XML, and
that an external entity of the
message is not read and nested entities are not expanded for both Kamelets,
with the Camel defaults.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* test: the entity expansion check does not depend on the JDK version (JDK
21 and 25 word it differently)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: regenerate the catalog files after merging main
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 46 +++++++-
docs/modules/ROOT/nav.adoc | 2 +
kamelets/xml-schema-validator-action.kamelet.yaml | 75 ++++++++++++
kamelets/xslt-action.kamelet.yaml | 71 +++++++++++
.../main/resources/META-INF/kamelets-index.json | 20 ++++
.../xml-schema-validator-action.kamelet.yaml | 75 ++++++++++++
.../resources/kamelets/xslt-action.kamelet.yaml | 71 +++++++++++
.../camel-kamelets-itest/src/test/java/XmlIT.java | 37 ++++++
.../src/test/resources/xml/templates/currency.xml | 18 +++
.../src/test/resources/xml/templates/lookup.xsl | 24 ++++
.../src/test/resources/xml/templates/order.xsd | 31 +++++
.../src/test/resources/xml/templates/order.xsl | 28 +++++
.../xml/xml-schema-validator-action-route.yaml | 131 +++++++++++++++++++++
.../xml/xml-schema-validator-action.citrus.it.yaml | 86 ++++++++++++++
.../src/test/resources/xml/xslt-action-route.yaml | 121 +++++++++++++++++++
.../test/resources/xml/xslt-action.citrus.it.yaml | 62 ++++++++++
16 files changed, 897 insertions(+), 1 deletion(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 7410e6ec2..e00a5fb4b 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -1116,6 +1116,16 @@
"type" : "library",
"name" : "xj-template-action",
"version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:xml-schema-validator-action",
+ "type" : "library",
+ "name" : "xml-schema-validator-action",
+ "version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:xslt-action",
+ "type" : "library",
+ "name" : "xslt-action",
+ "version" : "4.24.0-SNAPSHOT"
}, {
"bom-ref" : "pkg:maven/com.amazon.redshift/[email protected]",
"type" : "library",
@@ -2244,6 +2254,17 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-validator",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" : "pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
"type" : "library",
@@ -2277,6 +2298,17 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-xslt-saxon",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" : "pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.commons/[email protected]",
"type" : "library",
@@ -2308,7 +2340,7 @@
} ],
"dependencies" : [ {
"ref" : "camel-kamelets-catalog",
- "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-kinesis-firehose-sink",
"kamelet:aws-kinesis-sink", "kamelet:aws-kinesis- [...]
+ "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-kinesis-firehose-sink",
"kamelet:aws-kinesis-sink", "kamelet:aws-kinesis- [...]
}, {
"ref" : "kamelet:avro-deserialize-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -2972,6 +3004,12 @@
}, {
"ref" : "kamelet:xj-template-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:xml-schema-validator-action",
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:xslt-action",
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "pkg:maven/com.amazon.redshift/[email protected]",
"dependsOn" : [ ]
@@ -3284,6 +3322,9 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
@@ -3293,6 +3334,9 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.commons/[email protected]",
"dependsOn" : [ ]
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index c0eb7bf74..8807e2def 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -220,4 +220,6 @@
* xref:webhook-source.adoc[]
* xref:xj-identity-action.adoc[]
* xref:xj-template-action.adoc[]
+* xref:xml-schema-validator-action.adoc[]
+* xref:xslt-action.adoc[]
// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT
diff --git a/kamelets/xml-schema-validator-action.kamelet.yaml
b/kamelets/xml-schema-validator-action.kamelet.yaml
new file mode 100644
index 000000000..37360626a
--- /dev/null
+++ b/kamelets/xml-schema-validator-action.kamelet.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: xml-schema-validator-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "XML"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "XML Schema Validator Action"
+ description: |-
+ Checks that each XML message matches an XML Schema (XSD), and fails the
messages that do not.
+
+ Use it to stop bad data early, for example to reject the orders that
miss a required element or carry a wrong value before they reach another
system. For JSON, use `json-schema-validator-action`; to change the XML, use
`xslt-action`.
+
+ Input: XML as text, bytes or a stream.
+
+ Output: the same message, unchanged, when it matches the schema: text
stays text and bytes stay bytes.
+
+ Good to know: a message that does not match the schema, or that is not
XML, fails with an error that lists what is wrong, such as
`cvc-datatype-valid.1.2.1: 'abc' is not a valid value for 'decimal'.`; it is
not dropped silently, so the error handling of the integration decides what
happens to it. A message whose DOCTYPE has an entity that points to a file or
URL fails, and so does one with entities nested so deep that they pass the
entity expansion limit of Java. The schema is load [...]
+ required:
+ - template
+ type: object
+ properties:
+ template:
+ title: Schema Location
+ description: "Where to load the XML Schema (XSD) from, not the XML
Schema itself: `file://` followed by the path of a file, `classpath://`
followed by a resource in the application, or an `http://` or `https://` URL."
+ type: string
+ example: "file:///etc/camel/order.xsd"
+ pattern: "^(http|https|file|classpath|ref|bean)://.*"
+ dataTypes:
+ in:
+ default: unchanged
+ types:
+ unchanged:
+ format: "application-x-unchanged"
+ description: "XML as text, bytes or a stream. It is read, not
changed."
+ out:
+ default: unchanged
+ types:
+ unchanged:
+ format: "application-x-unchanged"
+ description: "The body as it came in, of the same type."
+ dependencies:
+ - "camel:validator"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - to:
+ uri: "validator:{{template}}"
diff --git a/kamelets/xslt-action.kamelet.yaml
b/kamelets/xslt-action.kamelet.yaml
new file mode 100644
index 000000000..c3fa0d7e3
--- /dev/null
+++ b/kamelets/xslt-action.kamelet.yaml
@@ -0,0 +1,71 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: xslt-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "XSLT Action"
+ description: |-
+ Transforms each XML message with an XSLT stylesheet, for example to map
the XML of one system to the XML or text that another system expects.
+
+ Use it to rename, pick, reorder or compute the elements of XML
documents, such as the totals of an order, with a stylesheet you write. The
stylesheet can use XSLT 3.0, which Saxon runs. To convert between XML and JSON,
use `xj-identity-action` or `xj-template-action`; to check XML against an XML
Schema, use `xml-schema-validator-action`.
+
+ Input: XML as text, bytes or a stream. A header whose name is a
parameter of the stylesheet sets that parameter: with `<xsl:param
name="channel" select="'web'"/>`, a `channel` header with the value `shop`
makes `$channel` give `shop`; without the header it gives `web`.
+
+ Output: the body is the result as text (a String): XML, or plain text
when the `xsl:output` of the stylesheet says `method="text"`. The
`Content-Type` header is not set. The other headers are kept.
+
+ Good to know: a body that is not XML fails the message. The DOCTYPE of
the message is not used: its entities are not expanded and an entity that
points to a file or URL is not read, so `&name;` gives nothing. A message can
set every parameter of the stylesheet with a header, so do not let a parameter
choose which resource the stylesheet reads. The stylesheet is code you write
and trust: XSLT functions such as `document()` can read other resources, such
as XML from the classpath. Th [...]
+ required:
+ - template
+ type: object
+ properties:
+ template:
+ title: Template
+ description: "Where to load the XSLT stylesheet from, not the
stylesheet itself: `file://` followed by the path of a file, `classpath://`
followed by a resource in the application, or an `http://` or `https://` URL."
+ type: string
+ example: "file:///opt/templates/order.xsl"
+ pattern: "^(http|https|file|classpath|ref|bean)://.*"
+ dataTypes:
+ # No 'default:' here on purpose: the stylesheet can write XML, text or
JSON, and a default would set
+ # the Content-Type header to one of them for all. See #3117.
+ in:
+ headers: {}
+ out:
+ headers: {}
+ dependencies:
+ - "camel:xslt-saxon"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - removeHeaders:
+ pattern: CamelXslt*
+ - to:
+ uri: "xslt-saxon:{{template}}"
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 0cc477b4b..7150c3da6 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -2209,5 +2209,25 @@
"group" : "Actions",
"namespace" : "Transformation",
"provider" : "Apache Software Foundation"
+ }, {
+ "name" : "xml-schema-validator-action",
+ "type" : "action",
+ "supportLevel" : "Stable",
+ "title" : "XML Schema Validator Action",
+ "summary" : "Checks that each XML message matches an XML Schema (XSD), and
fails the messages that do not.",
+ "description" : "Checks that each XML message matches an XML Schema (XSD),
and fails the messages that do not.\n\nUse it to stop bad data early, for
example to reject the orders that miss a required element or carry a wrong
value before they reach another system. For JSON, use
`json-schema-validator-action`; to change the XML, use `xslt-action`.\n\nInput:
XML as text, bytes or a stream.\n\nOutput: the same message, unchanged, when it
matches the schema: text stays text and bytes stay [...]
+ "group" : "Actions",
+ "namespace" : "XML",
+ "provider" : "Apache Software Foundation"
+ }, {
+ "name" : "xslt-action",
+ "type" : "action",
+ "supportLevel" : "Stable",
+ "title" : "XSLT Action",
+ "summary" : "Transforms each XML message with an XSLT stylesheet, for
example to map the XML of one system to the XML or text that another system
expects.",
+ "description" : "Transforms each XML message with an XSLT stylesheet, for
example to map the XML of one system to the XML or text that another system
expects.\n\nUse it to rename, pick, reorder or compute the elements of XML
documents, such as the totals of an order, with a stylesheet you write. The
stylesheet can use XSLT 3.0, which Saxon runs. To convert between XML and JSON,
use `xj-identity-action` or `xj-template-action`; to check XML against an XML
Schema, use `xml-schema-valid [...]
+ "group" : "Actions",
+ "namespace" : "Transformation",
+ "provider" : "Apache Software Foundation"
} ]
}
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/xml-schema-validator-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/xml-schema-validator-action.kamelet.yaml
new file mode 100644
index 000000000..37360626a
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/xml-schema-validator-action.kamelet.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: xml-schema-validator-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "XML"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "XML Schema Validator Action"
+ description: |-
+ Checks that each XML message matches an XML Schema (XSD), and fails the
messages that do not.
+
+ Use it to stop bad data early, for example to reject the orders that
miss a required element or carry a wrong value before they reach another
system. For JSON, use `json-schema-validator-action`; to change the XML, use
`xslt-action`.
+
+ Input: XML as text, bytes or a stream.
+
+ Output: the same message, unchanged, when it matches the schema: text
stays text and bytes stay bytes.
+
+ Good to know: a message that does not match the schema, or that is not
XML, fails with an error that lists what is wrong, such as
`cvc-datatype-valid.1.2.1: 'abc' is not a valid value for 'decimal'.`; it is
not dropped silently, so the error handling of the integration decides what
happens to it. A message whose DOCTYPE has an entity that points to a file or
URL fails, and so does one with entities nested so deep that they pass the
entity expansion limit of Java. The schema is load [...]
+ required:
+ - template
+ type: object
+ properties:
+ template:
+ title: Schema Location
+ description: "Where to load the XML Schema (XSD) from, not the XML
Schema itself: `file://` followed by the path of a file, `classpath://`
followed by a resource in the application, or an `http://` or `https://` URL."
+ type: string
+ example: "file:///etc/camel/order.xsd"
+ pattern: "^(http|https|file|classpath|ref|bean)://.*"
+ dataTypes:
+ in:
+ default: unchanged
+ types:
+ unchanged:
+ format: "application-x-unchanged"
+ description: "XML as text, bytes or a stream. It is read, not
changed."
+ out:
+ default: unchanged
+ types:
+ unchanged:
+ format: "application-x-unchanged"
+ description: "The body as it came in, of the same type."
+ dependencies:
+ - "camel:validator"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - to:
+ uri: "validator:{{template}}"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/xslt-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/xslt-action.kamelet.yaml
new file mode 100644
index 000000000..c3fa0d7e3
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/xslt-action.kamelet.yaml
@@ -0,0 +1,71 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: xslt-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "XSLT Action"
+ description: |-
+ Transforms each XML message with an XSLT stylesheet, for example to map
the XML of one system to the XML or text that another system expects.
+
+ Use it to rename, pick, reorder or compute the elements of XML
documents, such as the totals of an order, with a stylesheet you write. The
stylesheet can use XSLT 3.0, which Saxon runs. To convert between XML and JSON,
use `xj-identity-action` or `xj-template-action`; to check XML against an XML
Schema, use `xml-schema-validator-action`.
+
+ Input: XML as text, bytes or a stream. A header whose name is a
parameter of the stylesheet sets that parameter: with `<xsl:param
name="channel" select="'web'"/>`, a `channel` header with the value `shop`
makes `$channel` give `shop`; without the header it gives `web`.
+
+ Output: the body is the result as text (a String): XML, or plain text
when the `xsl:output` of the stylesheet says `method="text"`. The
`Content-Type` header is not set. The other headers are kept.
+
+ Good to know: a body that is not XML fails the message. The DOCTYPE of
the message is not used: its entities are not expanded and an entity that
points to a file or URL is not read, so `&name;` gives nothing. A message can
set every parameter of the stylesheet with a header, so do not let a parameter
choose which resource the stylesheet reads. The stylesheet is code you write
and trust: XSLT functions such as `document()` can read other resources, such
as XML from the classpath. Th [...]
+ required:
+ - template
+ type: object
+ properties:
+ template:
+ title: Template
+ description: "Where to load the XSLT stylesheet from, not the
stylesheet itself: `file://` followed by the path of a file, `classpath://`
followed by a resource in the application, or an `http://` or `https://` URL."
+ type: string
+ example: "file:///opt/templates/order.xsl"
+ pattern: "^(http|https|file|classpath|ref|bean)://.*"
+ dataTypes:
+ # No 'default:' here on purpose: the stylesheet can write XML, text or
JSON, and a default would set
+ # the Content-Type header to one of them for all. See #3117.
+ in:
+ headers: {}
+ out:
+ headers: {}
+ dependencies:
+ - "camel:xslt-saxon"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - removeHeaders:
+ pattern: CamelXslt*
+ - to:
+ uri: "xslt-saxon:{{template}}"
diff --git a/tests/camel-kamelets-itest/src/test/java/XmlIT.java
b/tests/camel-kamelets-itest/src/test/java/XmlIT.java
new file mode 100644
index 000000000..170d1dac5
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/java/XmlIT.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+import java.util.stream.Stream;
+
+import org.citrusframework.api.common.TestLoader;
+import org.citrusframework.junit.jupiter.CitrusSupport;
+import org.citrusframework.junit.jupiter.CitrusTestFactory;
+import org.citrusframework.junit.jupiter.CitrusTestFactorySupport;
+import org.junit.jupiter.api.DynamicTest;
+
+/**
+ * The XML Kamelets: xslt-action and xml-schema-validator-action. The tests
check the Camel log, so they need no
+ * server or container.
+ */
+@CitrusSupport
+public class XmlIT {
+
+ @CitrusTestFactory
+ public Stream<DynamicTest> xml() {
+ return
CitrusTestFactorySupport.factory(TestLoader.YAML).packageScan("xml");
+ }
+}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/templates/currency.xml
b/tests/camel-kamelets-itest/src/test/resources/xml/templates/currency.xml
new file mode 100644
index 000000000..350cbfd37
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/xml/templates/currency.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+<currency code="EUR"/>
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/templates/lookup.xsl
b/tests/camel-kamelets-itest/src/test/resources/xml/templates/lookup.xsl
new file mode 100644
index 000000000..478a7f5db
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/xml/templates/lookup.xsl
@@ -0,0 +1,24 @@
+<?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.
+-->
+<!-- reads another XML document of the classpath with document() -->
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="text"/>
+ <xsl:template match="/order">
+ <xsl:value-of select="customer"/> pays in <xsl:value-of
select="document('classpath:currency.xml')/currency/@code"/>
+ </xsl:template>
+</xsl:stylesheet>
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsd
b/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsd
new file mode 100644
index 000000000..bad07c15c
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsd
@@ -0,0 +1,31 @@
+<?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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="order">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="item" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="price" type="xs:decimal" use="required"/>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsl
b/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsl
new file mode 100644
index 000000000..59fe436c6
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/xml/templates/order.xsl
@@ -0,0 +1,28 @@
+<?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.
+-->
+<!-- An XSLT 3.0 stylesheet: upper-case() and the attribute value templates
need XSLT 2.0 or later -->
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml" omit-xml-declaration="yes"/>
+ <!-- set by the message header of the same name -->
+ <xsl:param name="channel" select="'web'"/>
+ <xsl:template match="/order">
+ <invoice channel="{$channel}" items="{count(item)}"
total="{sum(item/@price)}">
+ <customer><xsl:value-of select="upper-case(customer)"/></customer>
+ </invoice>
+ </xsl:template>
+</xsl:stylesheet>
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action-route.yaml
new file mode 100644
index 000000000..19c422eb2
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action-route.yaml
@@ -0,0 +1,131 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+# A valid document passes unchanged: a String stays a String
+- route:
+ from:
+ uri: "timer:valid"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><customer>Ann</customer><item
price="2.5"/></order>'
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "Valid ${body.getClass().getName()}: ${body}|"
+# and bytes stay bytes
+- route:
+ from:
+ uri: "timer:validbytes"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><customer>Bob</customer><item price="1"/><item
price="3"/></order>'
+ - convertBodyTo:
+ type: "byte[]"
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "ValidBytes ${body.getClass().getName()}: ${bodyAs(String)}|"
+# An invalid document fails the message with the list of what is wrong
+- route:
+ from:
+ uri: "timer:invalid"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><item price="abc"/></order>'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "Accepted-invalid ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected-invalid ${exception.getClass().getName()}:
${exception.message}"
+# An external entity of the message is not read: the message fails
+- route:
+ from:
+ uri: "timer:xxe"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<?xml version="1.0"?><!DOCTYPE order [<!ENTITY hosts
SYSTEM "file:///etc/hosts">]><order><customer>&hosts;</customer><item
price="1"/></order>'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "Accepted-xxe ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected-xxe ${exception.getClass().getName()}:
${exception.message}"
+# Nested entities (a billion laughs) stop at the entity expansion limit of the
JDK: the message fails
+- route:
+ from:
+ uri: "timer:bomb"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<?xml version="1.0"?><!DOCTYPE order [<!ENTITY a
"aaaaaaaaaa"><!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;"><!ENTITY c
"&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"><!ENTITY d
"&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"><!ENTITY e
"&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"><!ENTITY f
"&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"><!ENTITY g
"&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"><!ENTITY h
"&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"><!ENTITY i
"&h;&h;&h;&h;&h;&h;&h;&h;&h;&h;">]><order><customer>&i;</customer><item
price="1"/></order>'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "Accepted-bomb ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected-bomb ${exception.getClass().getName()}:
${exception.message}"
+# A body that is not XML fails the message
+- route:
+ from:
+ uri: "timer:text"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: 'not xml'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xml-schema-validator-action"
+ parameters:
+ template: "classpath:order.xsd"
+ - log: "Accepted-text ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected-text ${exception.getClass().getName()}:
${exception.message}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action.citrus.it.yaml
new file mode 100644
index 000000000..d884825f7
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/xml/xml-schema-validator-action.citrus.it.yaml
@@ -0,0 +1,86 @@
+# ---------------------------------------------------------------------------
+# 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: xml-schema-validator-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ resources:
+ - "templates/order.xsd"
+ integration:
+ file: "xml/xml-schema-validator-action-route.yaml"
+ # A valid document passes unchanged, of the same type
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Valid java.lang.String:
<order><customer>Ann</customer><item price="2.5"/></order>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'ValidBytes [B: <order><customer>Bob</customer><item
price="1"/><item price="3"/></order>|'
+ # An invalid document fails with the list of what is wrong
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Rejected-invalid
org.apache.camel.support.processor.validation.SchemaValidationException:
Validation failed for'
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: "cvc-complex-type.2.4.a: Invalid content was found
starting with element 'item'. One of '{customer}' is expected."
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: "cvc-datatype-valid.1.2.1: 'abc' is not a valid value
for 'decimal'."
+ # The external entity is not read: the message fails
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Rejected-xxe
org.apache.camel.support.processor.validation.SchemaValidationException'
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: "Failed to read external document 'hosts', because
'file' access is not allowed due to restriction set by the accessExternalDTD
property."
+ # The nested entities stop at the entity expansion limit of the JDK (its
number differs per JDK version)
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Rejected-bomb
org.apache.camel.support.processor.validation.SchemaValidationException'
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'entity expansions in this document; this is the limit
imposed by'
+ # A body that is not XML fails
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Rejected-text
org.apache.camel.support.processor.validation.SchemaValidationException'
+ - camel:
+ cli:
+ verify:
+ integration: "xml-schema-validator-action-route"
+ logMessage: 'Content is not allowed in prolog.'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action-route.yaml
new file mode 100644
index 000000000..f9fac5f6b
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action-route.yaml
@@ -0,0 +1,121 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+# A transformation with a parameter set by a header, from a String
+- route:
+ from:
+ uri: "timer:param"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><customer>Ann</customer><item price="2.5"/><item
price="4"/></order>'
+ - setHeader:
+ name: channel
+ constant: "shop"
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:order.xsl"
+ - log: "Param ${body.getClass().getName()} ct=${header.Content-Type}
channel=${header.channel}: ${body}|"
+# The default of the parameter, from bytes; headers that start with CamelXslt
cannot choose another stylesheet
+- route:
+ from:
+ uri: "timer:bytes"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><customer>Bob</customer><item
price="1"/></order>'
+ - convertBodyTo:
+ type: "byte[]"
+ - setHeader:
+ name: CamelXsltResourceUri
+ constant: "classpath:lookup.xsl"
+ - setHeader:
+ name: CamelXsltStylesheet
+ constant: '<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
match="/">REPLACED</xsl:template></xsl:stylesheet>'
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:order.xsl"
+ - log: "Bytes ${body}|"
+# document() reads another XML document from the classpath
+- route:
+ from:
+ uri: "timer:lookup"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<order><customer>Cid</customer></order>'
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:lookup.xsl"
+ - log: "Lookup ${body}|"
+# An external entity of the message is not read, from a stream
+- route:
+ from:
+ uri: "timer:xxe"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<?xml version="1.0"?><!DOCTYPE order [<!ENTITY hosts
SYSTEM "file:///etc/hosts">]><order><customer>&hosts;</customer></order>'
+ - convertBodyTo:
+ type: "java.io.InputStream"
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:order.xsl"
+ - log: "Xxe ${body}|"
+# Nested entities (a billion laughs) are not expanded
+- route:
+ from:
+ uri: "timer:bomb"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '<?xml version="1.0"?><!DOCTYPE order [<!ENTITY a
"aaaaaaaaaa"><!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;"><!ENTITY c
"&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"><!ENTITY d
"&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"><!ENTITY e
"&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"><!ENTITY f
"&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"><!ENTITY g
"&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"><!ENTITY h
"&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"><!ENTITY i
"&h;&h;&h;&h;&h;&h;&h;&h;&h;&h;">]><order><customer>&i;</customer></order>'
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:order.xsl"
+ - log: "Bomb ${body}|"
+# A body that is not XML fails the message
+- route:
+ from:
+ uri: "timer:text"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: 'not xml'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xslt-action"
+ parameters:
+ template: "classpath:order.xsl"
+ - log: "Accepted ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected ${exception.getClass().getName()}:
${exception.message}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action.citrus.it.yaml
new file mode 100644
index 000000000..fae4c00b4
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/xml/xslt-action.citrus.it.yaml
@@ -0,0 +1,62 @@
+# ---------------------------------------------------------------------------
+# 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: xslt-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ resources:
+ - "templates/order.xsl"
+ - "templates/lookup.xsl"
+ - "templates/currency.xml"
+ integration:
+ file: "xml/xslt-action-route.yaml"
+ # An XSLT 3.0 stylesheet, with its parameter set by a header; the body is a
String and no Content-Type is set
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Param java.lang.String ct= channel=shop: <invoice
channel="shop" items="2" total="6.5"><customer>ANN</customer></invoice>|'
+ # Bytes in, and the parameter keeps its default; the CamelXslt headers are
removed, so they do not replace the stylesheet
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Bytes <invoice channel="web" items="1"
total="1"><customer>BOB</customer></invoice>|'
+ # document() reads XML from the classpath
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Lookup Cid pays in EUR|'
+ # The external entity is not read and the nested entities are not expanded:
the DOCTYPE of the message is not used
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Xxe <invoice channel="web" items="0"
total="0"><customer/></invoice>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Bomb <invoice channel="web" items="0"
total="0"><customer/></invoice>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xslt-action-route"
+ logMessage: 'Rejected net.sf.saxon.trans.XPathException: Error
reported by XML parser: Content is not allowed in prolog.'