davsclaus opened a new pull request, #3378:
URL: https://github.com/apache/camel-kamelets/pull/3378

   ## What
   
   A new **`xpath-filter-action`** Kamelet (Preview), on the Camel `xpath` 
language: it keeps the XML messages that match an XPath expression and drops 
the others. The XML counterpart of `predicate-filter-action` (JSONPath).
   
   ```yaml
   - to:
       uri: "kamelet:xpath-filter-action"
       parameters:
         expression: "/o:order[o:status = 'paid']"
         namespacePrefix: "o"
         namespaceUri: "urn:example:orders"
   ```
   
   ### Options
   
   - `expression` (required): the XPath 1.0 expression a message must match to 
be kept, e.g. `/order[amount > 100]` or `/order/customer = 'Ann'`.
   - `namespacePrefix` / `namespaceUri` (optional, default empty): one 
namespace prefix to use in the expression. For more than one namespace, the 
description shows `local-name()` / `namespace-uri()`.
   
   ### Input / Output
   
   - Input: XML as text, bytes or a stream.
   - Output: the same message, unchanged (text stays text, bytes stay bytes, a 
stream can still be read, the headers are kept) when the expression matches; 
otherwise the message is dropped.
   
   ### Design choices
   
   - **Template:** `choice` → `when` xpath (no steps) / `otherwise` → `stop`. 
The expression is not wrapped in a string such as `not(...)`.
   - **Non-XML body fails rather than being dropped.** A dropped message could 
hide bad input, so the integration's error handling decides instead. This 
matches `xml-schema-validator-action`. A message without a body is dropped.
   - **XXE:** the xpath language turns the body into a DOM `Document` with 
Camel's `XmlConverter`, which sets `disallow-doctype-decl`, secure processing 
and no external general entities. So any body with a DOCTYPE fails, and no 
entity is expanded or read. No extra setting is needed; the test proves it with 
an external entity on `file:///etc/hosts`.
   - **Security model:** the expression is a Kamelet property, never message 
data. The Kamelet reads no `Camel*` header that could change what it does.
   - `spec.dataTypes`: `application-x-unchanged` for in and out, the same as 
the other filter actions.
   
   ## Tests
   
   
`tests/camel-kamelets-itest/src/test/resources/xml/xpath-filter-action*.yaml`, 
in the existing `XmlIT` (log-based, no container). Each timer sends numbered 
messages in turn. The last message logs which numbers were kept, so the test 
checks the dropped messages as well as the kept ones:
   
   - A match, as text, bytes and a stream, is kept unchanged with its headers; 
a condition (`/order/customer = 'Ann'`) that is true keeps the message.
   - No match: a lower amount, a missing element, no body and a false condition 
are dropped (`Plain kept: 1,3,4,7,`).
   - Namespace: the prefixed expression keeps the namespaced paid order. It 
drops the open order and the order without a namespace. A name without a prefix 
does not match the namespaced element, and `local-name()`/`namespace-uri()` 
does (`Namespace kept: 1,5,`).
   - A body with a DOCTYPE and an external entity fails with `DOCTYPE is 
disallowed ...`.
   - A body that is not XML fails with `Content is not allowed in prolog.`
   
   Local results: `./mvnw -o clean install -DskipITs` OK; `XmlIT`: 3 tests, 0 
failures (the xslt, validator and new xpath-filter tests).
   
   Fixes #3375.
   
   ## Upgrade note
   
   - New Kamelet `xpath-filter-action` (Preview): keeps the XML messages that 
match an XPath expression and drops the others. It can use one namespace 
prefix. A body that is not XML, or that has a DOCTYPE, fails the message.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to