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 cd5749710 Fix #3375: new xpath-filter-action Kamelet, keep the XML
messages that match an XPath expression (#3378)
cd5749710 is described below
commit cd57497104aaee465871c7b2f55b1849c21d7438
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 16:05:32 2026 +0100
Fix #3375: new xpath-filter-action Kamelet, keep the XML messages that
match an XPath expression (#3378)
* Fix #3375: new xpath-filter-action Kamelet, keep the XML messages that
match an XPath expression
The expression is a Kamelet option (never message data), with an optional
namespace prefix. A body that is not XML fails rather than being dropped,
and
a body with a DOCTYPE fails, so no entity is expanded or read (Camel's
XmlConverter disallows DOCTYPE declarations). Preview.
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 | 10 +-
docs/modules/ROOT/nav.adoc | 1 +
kamelets/xpath-filter-action.kamelet.yaml | 96 +++++++++++
.../main/resources/META-INF/kamelets-index.json | 10 ++
.../kamelets/xpath-filter-action.kamelet.yaml | 96 +++++++++++
.../camel-kamelets-itest/src/test/java/XmlIT.java | 4 +-
.../resources/xml/xpath-filter-action-route.yaml | 176 +++++++++++++++++++++
.../xml/xpath-filter-action.citrus.it.yaml | 86 ++++++++++
8 files changed, 476 insertions(+), 3 deletions(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index d58769aa6..970d4334d 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -1186,6 +1186,11 @@
"type" : "library",
"name" : "xml-schema-validator-action",
"version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:xpath-filter-action",
+ "type" : "library",
+ "name" : "xpath-filter-action",
+ "version" : "4.24.0-SNAPSHOT"
}, {
"bom-ref" : "kamelet:xslt-action",
"type" : "library",
@@ -2511,7 +2516,7 @@
} ],
"dependencies" : [ {
"ref" : "camel-kamelets-catalog",
- "dependsOn" : [ "kamelet:ai-tool-source",
"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-eventbridge-source", "kamelet:aws-kinesis-fireh [...]
+ "dependsOn" : [ "kamelet:ai-tool-source",
"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-eventbridge-source", "kamelet:aws-kinesis-fireh [...]
}, {
"ref" : "kamelet:ai-tool-source",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3217,6 +3222,9 @@
}, {
"ref" : "kamelet:xml-schema-validator-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:xpath-filter-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]" ]
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 7b7b376b2..3afd7f66d 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -234,5 +234,6 @@
* xref:xj-identity-action.adoc[]
* xref:xj-template-action.adoc[]
* xref:xml-schema-validator-action.adoc[]
+* xref:xpath-filter-action.adoc[]
* xref:xslt-action.adoc[]
// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT
diff --git a/kamelets/xpath-filter-action.kamelet.yaml
b/kamelets/xpath-filter-action.kamelet.yaml
new file mode 100644
index 000000000..0aec7bfdd
--- /dev/null
+++ b/kamelets/xpath-filter-action.kamelet.yaml
@@ -0,0 +1,96 @@
+# ---------------------------------------------------------------------------
+# 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: xpath-filter-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ 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: "EIP"
+spec:
+ definition:
+ title: "XPath Filter Action"
+ description: |-
+ Keeps only the XML messages that match an XPath expression, and drops
all others.
+
+ Use it to pass on only the XML documents you care about, for example
only the orders above a certain amount with `/order[amount > 100]`, or only the
paid invoices of an XML feed. For JSON, use `predicate-filter-action`; to keep
or drop messages by a header, use `header-matches-filter-action`; to check XML
against an XML Schema, use `xml-schema-validator-action`.
+
+ Input: XML as text, bytes or a stream.
+
+ Output: the same message, unchanged, when the expression matches: text
stays text, bytes stay bytes, a stream can still be read, and the headers are
kept. When it does not match, the message is dropped and nothing is sent on.
+
+ Good to know: the expression matches when it selects at least one
element, such as `/order[amount > 100]`, or when it is a condition that is
true, such as `/order/customer = 'Ann'`. A message without a body is dropped. A
body that is not XML fails with an error such as `Content is not allowed in
prolog.`; it is not dropped silently, so the error handling of the integration
decides what happens to it. A message with a DOCTYPE fails too, so its entities
are never expanded and an enti [...]
+ required:
+ - expression
+ type: object
+ properties:
+ expression:
+ title: Expression
+ description: "The XPath 1.0 expression a message must match to be
kept. For example, `/order[amount > 100]` keeps the orders whose `amount`
element is more than 100, and `/order/customer = 'Ann'` those of the customer
Ann."
+ type: string
+ example: "/order[amount > 100]"
+ namespacePrefix:
+ title: Namespace Prefix
+ description: "A prefix to use in the expression for the namespace
given by `namespaceUri`. For example, with the prefix `o` and the namespace
`urn:example:orders`, `/o:order[o:status = 'paid']` keeps the paid orders of
`<order xmlns=\"urn:example:orders\">`. An element in a namespace is not
matched by a name without a prefix."
+ type: string
+ default: ""
+ example: "o"
+ namespaceUri:
+ title: Namespace URI
+ description: "The namespace that `namespacePrefix` stands for, as
written in the `xmlns` attribute of the XML."
+ type: string
+ default: ""
+ example: "urn:example:orders"
+ 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:kamelet"
+ - "camel:xpath"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - choice:
+ when:
+ - expression:
+ xpath:
+ expression: "{{expression}}"
+ namespace:
+ - key: "{{namespacePrefix}}"
+ value: "{{namespaceUri}}"
+ steps: []
+ otherwise:
+ steps:
+ - stop: {}
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 cf154d752..d79a0bc9b 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
@@ -2349,6 +2349,16 @@
"group" : "Actions",
"namespace" : "XML",
"provider" : "Apache Software Foundation"
+ }, {
+ "name" : "xpath-filter-action",
+ "type" : "action",
+ "supportLevel" : "Preview",
+ "title" : "XPath Filter Action",
+ "summary" : "Keeps only the XML messages that match an XPath expression,
and drops all others.",
+ "description" : "Keeps only the XML messages that match an XPath
expression, and drops all others.\n\nUse it to pass on only the XML documents
you care about, for example only the orders above a certain amount with
`/order[amount > 100]`, or only the paid invoices of an XML feed. For JSON, use
`predicate-filter-action`; to keep or drop messages by a header, use
`header-matches-filter-action`; to check XML against an XML Schema, use
`xml-schema-validator-action`.\n\nInput: XML as text [...]
+ "group" : "Actions",
+ "namespace" : "EIP",
+ "provider" : "Apache Software Foundation"
}, {
"name" : "xslt-action",
"type" : "action",
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/xpath-filter-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/xpath-filter-action.kamelet.yaml
new file mode 100644
index 000000000..0aec7bfdd
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/xpath-filter-action.kamelet.yaml
@@ -0,0 +1,96 @@
+# ---------------------------------------------------------------------------
+# 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: xpath-filter-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ 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: "EIP"
+spec:
+ definition:
+ title: "XPath Filter Action"
+ description: |-
+ Keeps only the XML messages that match an XPath expression, and drops
all others.
+
+ Use it to pass on only the XML documents you care about, for example
only the orders above a certain amount with `/order[amount > 100]`, or only the
paid invoices of an XML feed. For JSON, use `predicate-filter-action`; to keep
or drop messages by a header, use `header-matches-filter-action`; to check XML
against an XML Schema, use `xml-schema-validator-action`.
+
+ Input: XML as text, bytes or a stream.
+
+ Output: the same message, unchanged, when the expression matches: text
stays text, bytes stay bytes, a stream can still be read, and the headers are
kept. When it does not match, the message is dropped and nothing is sent on.
+
+ Good to know: the expression matches when it selects at least one
element, such as `/order[amount > 100]`, or when it is a condition that is
true, such as `/order/customer = 'Ann'`. A message without a body is dropped. A
body that is not XML fails with an error such as `Content is not allowed in
prolog.`; it is not dropped silently, so the error handling of the integration
decides what happens to it. A message with a DOCTYPE fails too, so its entities
are never expanded and an enti [...]
+ required:
+ - expression
+ type: object
+ properties:
+ expression:
+ title: Expression
+ description: "The XPath 1.0 expression a message must match to be
kept. For example, `/order[amount > 100]` keeps the orders whose `amount`
element is more than 100, and `/order/customer = 'Ann'` those of the customer
Ann."
+ type: string
+ example: "/order[amount > 100]"
+ namespacePrefix:
+ title: Namespace Prefix
+ description: "A prefix to use in the expression for the namespace
given by `namespaceUri`. For example, with the prefix `o` and the namespace
`urn:example:orders`, `/o:order[o:status = 'paid']` keeps the paid orders of
`<order xmlns=\"urn:example:orders\">`. An element in a namespace is not
matched by a name without a prefix."
+ type: string
+ default: ""
+ example: "o"
+ namespaceUri:
+ title: Namespace URI
+ description: "The namespace that `namespacePrefix` stands for, as
written in the `xmlns` attribute of the XML."
+ type: string
+ default: ""
+ example: "urn:example:orders"
+ 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:kamelet"
+ - "camel:xpath"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - choice:
+ when:
+ - expression:
+ xpath:
+ expression: "{{expression}}"
+ namespace:
+ - key: "{{namespacePrefix}}"
+ value: "{{namespaceUri}}"
+ steps: []
+ otherwise:
+ steps:
+ - stop: {}
diff --git a/tests/camel-kamelets-itest/src/test/java/XmlIT.java
b/tests/camel-kamelets-itest/src/test/java/XmlIT.java
index 170d1dac5..a69dc561e 100644
--- a/tests/camel-kamelets-itest/src/test/java/XmlIT.java
+++ b/tests/camel-kamelets-itest/src/test/java/XmlIT.java
@@ -24,8 +24,8 @@ 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.
+ * The XML Kamelets: xslt-action, xml-schema-validator-action and
xpath-filter-action. The tests check the Camel log,
+ * so they need no server or container.
*/
@CitrusSupport
public class XmlIT {
diff --git
a/tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-action-route.yaml
new file mode 100644
index 000000000..58c19e5f3
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-action-route.yaml
@@ -0,0 +1,176 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+# Each timer sends its messages one after the other. A message that the
Kamelet keeps is logged and its number added to
+# a list; the last message logs the list, so it shows the messages that were
dropped too.
+- route:
+ from:
+ uri: "timer:plain"
+ parameters:
+ repeatCount: 9
+ period: 10
+ includeMetadata: true
+ steps:
+ - setHeader:
+ name: X-Order
+ constant: "kept"
+ - choice:
+ when:
+ - simple: "${header.CamelTimerCounter} == 1"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Ann</customer><amount>150</amount></order>'
+ - simple: "${header.CamelTimerCounter} == 2"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Bob</customer><amount>20</amount></order>'
+ - simple: "${header.CamelTimerCounter} == 3"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Cid</customer><amount>300</amount></order>'
+ - convertBodyTo:
+ type: "byte[]"
+ - simple: "${header.CamelTimerCounter} == 4"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Dan</customer><amount>400</amount></order>'
+ - convertBodyTo:
+ type: "java.io.InputStream"
+ - simple: "${header.CamelTimerCounter} == 5"
+ steps:
+ - setBody:
+ constant: '<order><customer>Eve</customer></order>'
+ - simple: "${header.CamelTimerCounter} == 7"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Ann</customer><amount>1</amount></order>'
+ - simple: "${header.CamelTimerCounter} == 8"
+ steps:
+ - setBody:
+ constant:
'<order><customer>Bob</customer><amount>500</amount></order>'
+ - simple: "${header.CamelTimerCounter} == 9"
+ steps:
+ - log: "Plain kept: ${variable.global:plain}|"
+ - stop: {}
+ - choice:
+ when:
+ - simple: "${header.CamelTimerCounter} >= 7"
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/order/customer = 'Ann'"
+ otherwise:
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/order[amount > 100]"
+ - log: "Kept ${header.CamelTimerCounter} ${body.getClass().getName()}
ct=${header.Content-Type} order=${header.X-Order}: ${bodyAs(String)}|"
+ - setVariable:
+ name: "global:plain"
+ simple: "${variable.global:plain}${header.CamelTimerCounter},"
+- route:
+ from:
+ uri: "timer:ns"
+ parameters:
+ repeatCount: 6
+ period: 10
+ includeMetadata: true
+ steps:
+ - setBody:
+ constant: '<order
xmlns="urn:example:orders"><status>paid</status></order>'
+ - choice:
+ when:
+ - simple: "${header.CamelTimerCounter} == 2"
+ steps:
+ - setBody:
+ constant: '<order
xmlns="urn:example:orders"><status>open</status></order>'
+ - simple: "${header.CamelTimerCounter} == 3"
+ steps:
+ - setBody:
+ constant: '<order><status>paid</status></order>'
+ - simple: "${header.CamelTimerCounter} == 6"
+ steps:
+ - log: "Namespace kept: ${variable.global:ns}|"
+ - stop: {}
+ - choice:
+ when:
+ # Without a prefix, the name does not match the element in the
namespace
+ - simple: "${header.CamelTimerCounter} == 4"
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/order[status = 'paid']"
+ - simple: "${header.CamelTimerCounter} == 5"
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/*[local-name() = 'order' and
namespace-uri() = 'urn:example:orders']"
+ otherwise:
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/o:order[o:status = 'paid']"
+ namespacePrefix: "o"
+ namespaceUri: "urn:example:orders"
+ - log: "NsKept ${header.CamelTimerCounter}: ${body}|"
+ - setVariable:
+ name: "global:ns"
+ simple: "${variable.global:ns}${header.CamelTimerCounter},"
+- 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><amount>500</amount></order>'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/order[amount > 100]"
+ - log: "Accepted-xxe ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected-xxe ${exception.getClass().getName()}:
${exception.message}"
+- route:
+ from:
+ uri: "timer:text"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: 'not xml'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:xpath-filter-action"
+ parameters:
+ expression: "/order[amount > 100]"
+ - 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/xpath-filter-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-action.citrus.it.yaml
new file mode 100644
index 000000000..8d2575d10
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-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: xpath-filter-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ integration:
+ file: "xml/xpath-filter-action-route.yaml"
+ # A matching message is kept unchanged: text stays text, bytes stay bytes, a
stream can be read; the headers are kept
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Kept 1 java.lang.String ct= order=kept:
<order><customer>Ann</customer><amount>150</amount></order>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Kept 3 [B ct= order=kept:
<order><customer>Cid</customer><amount>300</amount></order>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Kept 4
org.apache.camel.converter.stream.ByteArrayInputStreamCache ct= order=kept:
<order><customer>Dan</customer><amount>400</amount></order>|'
+ # A condition that is true keeps the message
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Kept 7 java.lang.String ct= order=kept:
<order><customer>Ann</customer><amount>1</amount></order>|'
+ # Only 1, 3, 4 and 7 are kept: 2 (amount 20), 5 (no amount), 6 (no body) and
8 (customer Bob) are dropped
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Plain kept: 1,3,4,7,|'
+ # The namespace prefix matches the paid order in the namespace (1), not the
open one (2), nor the one without a
+ # namespace (3); a name without a prefix does not match an element in a
namespace (4); local-name() and
+ # namespace-uri() match it (5)
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'NsKept 1: <order
xmlns="urn:example:orders"><status>paid</status></order>|'
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Namespace kept: 1,5,|'
+ # A message with a DOCTYPE fails: the external entity is never read
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Rejected-xxe org.apache.camel.TypeConversionException'
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'DOCTYPE is disallowed when the feature
"http://apache.org/xml/features/disallow-doctype-decl" set to true.'
+ # A body that is not XML fails, it is not dropped silently
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Rejected-text org.apache.camel.TypeConversionException'
+ - camel:
+ cli:
+ verify:
+ integration: "xpath-filter-action-route"
+ logMessage: 'Content is not allowed in prolog.'