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

   Fixes [CAMEL-26062](https://issues.apache.org/jira/browse/CAMEL-26062).
   
   All five points of the issue were real. Each one is fixed in 
`SmooksProcessor` or `BeanRouter`.
   
   ### 1. `SAXSource` body
   - **Before:** the `XMLReader` of the `SAXSource` was cast to 
`java.io.Reader`, which threw a `ClassCastException`. With 
`allowExternalEntities=false` and no reader class in the config, the body found 
no converter.
   - **Now:** the body is read from its `InputSource`: the character stream, 
then the byte stream (decoded with the `InputSource` encoding when it has one), 
then the system id as a URL. The `XMLReader` is not used. A `SAXSource` with no 
input fails with `InvalidPayloadException`. With `allowExternalEntities=false`, 
the input goes through the same secure parse as the other XML bodies.
   
   ### 2. Remote file body (ftp, sftp, ftps) with a reader in the config
   - **Before:** `WrappedFile.getFile()` was cast to `java.io.File`, which 
threw a `ClassCastException` for an FTP or SFTP file.
   - **Now:** a local file is still read through its URL. Any other file is 
read from its downloaded content, using the `InputStream` converter of the file 
component.
   
   ### 3. `java.io.File` or `java.nio.file.Path` body with a reader in the 
config
   - **Before:** there is no converter to a Smooks `Source` for these types, so 
the body failed with `InvalidPayloadException`.
   - **Now:** both are read through their URL (`URLSource`), as a file from the 
file consumer already was.
   
   ### 4. Several exports
   - **Before:** Smooks creates the sinks in a `HashSet` 
(`Exports.createSinks()`), so the `List` body came in a random order.
   - **Now:** `SmooksProcessor` sorts the sinks by class name before filtering, 
so the order is fixed and documented (for example `JavaSink` before 
`StringSink`).
   
   ### 5. Bean route with a correlation id
   - **Before:** `ProducerTemplate.send(endpoint, processor)` does not throw: a 
failure of the endpoint was left on the returned exchange and ignored. The 
branch without a correlation id throws.
   - **Now:** the exception on the returned exchange is thrown, and it is 
wrapped in the same `SmooksException` as the other branch.
   
   ### Tests
   - New `SmooksReaderBodyTest` uses the EDI config, which declares a reader. 
It covers a SAXSource with a character stream, a byte stream and a system id, 
an empty SAXSource, a SAXSource parsed without external entities by the default 
reader, `File`, `Path`, a local `GenericFile`, a remote `GenericFile` (its file 
is not a `java.io.File`), and the order of two exports (checked over 20 sends).
   - `BeanRouterTest` has two new tests: a failing endpoint with and without a 
correlation id.
   - I stashed the fix and ran the new tests: 10 failed. The local 
`GenericFile` test and the bean route without a correlation id passed; they 
guard behaviour that already worked. With the fix, all 55 tests of the module 
pass (`mvn clean install -Psourcecheck`).
   
   ### Docs
   - `smooks-component.adoc` now lists the File, Path and remote file bodies, 
says that a SAXSource is read from its `InputSource`, and gives the order of 
several exports. The catalog copy is updated.
   - Upgrade guide 4.24: one entry. A bean route with a correlation id now 
fails the Smooks processing when its endpoint fails. Before, that failure was 
ignored.
   
   ### Not changed
   - `SourceConverter.toURISource(WrappedFile<File>)` casts `getBody()` to 
`File`, so it can fail the same way for a remote file. `SmooksProcessor` no 
longer uses it for file bodies. I did not change the converter because the 
issue does not list it.
   - With stream caching on (the default), Camel turns a `SAXSource` body into 
a String when the route starts (`StreamSourceConverter`), before Smooks sees 
it. That is core behaviour. The fix here covers a SAXSource that reaches the 
Smooks endpoint, for example one set by a processor, or in a route without 
stream caching.
   - In the correlation-id branch, the bean router still does not set the 
`CamelSmooksExecutionContext` header that the other branch sets. The issue does 
not list this.
   
   ### For review
   - The export order (class name of the sink type) is my choice. The Smooks 
configuration order cannot be used, because `Exports` keeps the exports in a 
`HashMap`.
   
   _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]

Reply via email to