davsclaus opened a new pull request, #28904: URL: https://github.com/apache/camel/pull/28904
Fixes [CAMEL-26126](https://issues.apache.org/jira/browse/CAMEL-26126). ### A byte[], Path or DOM Document body fails **What was wrong:** `StAXProcessor.process` read the body with `getMandatoryBody(XMLStreamReader.class)`. Core has no converter to `XMLStreamReader` from a `byte[]`, a `java.nio.file.Path` or a DOM `Document`, so these bodies failed with `InvalidPayloadException` (caused by `NoTypeConversionAvailableException`). A String, an InputStream, a File or a `Source` worked. **What changed:** the producer first tries the direct conversion to `XMLStreamReader`, as before. When there is none, it reads the body as an `InputStream` (core already converts `byte[]`, `Path` and `Document` to a stream) and converts that stream to an `XMLStreamReader`. That goes through the same `StaxConverter` and its secured `XMLInputFactory` (no DTD support, no external entities, the resolver throws). No new parser or factory is added. The producer closes the stream it opened, because closing the reader does not close it (for example the file handle of a `Path`). This is the same fallback `StAXJAXBIteratorExpression` in this component already uses for `XMLEventReader`. A `Map` or a missing body still fails with `InvalidPayloadException`, as before. **Tests:** new `StAXBodyTypesTest` sends a String, byte[], InputStream, File, Path, StreamSource and DOM Document body and checks the element count. It also checks that non-ASCII text in bytes is read correctly, that an external entity in a byte[] body is not resolved, and that a Map body still fails. Without the fix, 5 of the 10 tests fail (byte[], Path, Document, the non-ASCII bytes test and the external entity test). The module suite passes: 136 tests, 0 failures, 2 skipped (`mvn -o clean install -Psourcecheck`). **Docs and generated files:** the `@BodyTypes` description of `StAXEndpoint` now lists the accepted bodies and adds the `bytes` carrier (it used to say "Bytes, a DOM Document ... fail"). `stax.json` is regenerated and copied into camel-catalog. The component doc gets one sentence on the accepted bodies; the catalog copy is updated. No upgrade guide entry: bodies that failed now work; nothing that worked changes. **Not changed:** no new converters in core `StaxConverter` (camel-xml-jaxp). Adding `byte[]`/`Path`/`Node` to `XMLStreamReader` converters there would be a wider change to core type conversion, and a DOM node through a `DOMSource` only works with Woodstox (the JDK StAX factory does not accept a `DOMSource`). Reading the `Document` as a stream works with any StAX implementation. Core converters can still be added later if other components need them. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
