davsclaus opened a new pull request, #28909: URL: https://github.com/apache/camel/pull/28909
Fixes [CAMEL-26134](https://issues.apache.org/jira/browse/CAMEL-26134). All three bugs were in `CitrusValidationProcessor.buildReceivedMessage`, which only read a `StreamCache` body as text and handed any other body to Citrus as is. ### 1. A byte[] body never validated Citrus compared a `byte[]` as `[123, 34, ...]`, so JSON or text sent as bytes always failed. Now a `byte[]` body is converted to a String with the Camel type converter before the validation. ### 2. A File body was compared as its path A `java.io.File` (and a `java.nio.file.Path`) was compared as its `toString()`, the path. Now `File`, `Path` and `WrappedFile` (the `GenericFile` of the file consumers) bodies are read as text. ### 3. A plain InputStream was consumed With stream caching off, Citrus read a plain `InputStream` (and compared it as a list of numbers too), and the next step got an empty stream. A `Reader` was compared as `java.io.StringReader@...`. Now a plain `InputStream` or `Reader` is converted to a `StreamCache` and set back on the message first, then read and reset like before. ### Related fix on the same lines A stream cache was always read as a String, also for the binary message types. `BinaryBase64MessageValidator` and `GzipBinaryBase64MessageValidator` only work on a `byte[]` payload, so a stream cache never validated with `binary_base64`. For `binary`, `binary_base64`, `gzip` and `gzip_base64` the body is now read as bytes; for the other types as text. ### Tests New `CitrusValidateBodyTypesTest` (8 tests): byte[] with json and plaintext, a byte[] mismatch, File, Path, a plain InputStream and a Reader with stream caching off (the next step still gets the content), and a stream cache with `binary_base64`. 7 of them fail without the fix (the mismatch test passes either way). The module suite passes: 49 tests, 0 failures, with `-Psourcecheck`. ### Docs and generated files - The `producerIn` body type of `CitrusEndpoint` described the old behaviour ("bytes as a list of numbers, a file as its path"). It now lists text, bytes, stream and file, regenerated in the component JSON and copied to the catalog. - New "Message body types" section in `citrus-component.adoc`, copied to the catalog. - No upgrade guide entry: the component is new in 4.24. ### Not changed Other bodies (a `Map`, a POJO, a DOM `Document`, a `ByteBuffer`) are still handed to Citrus as is, so a Citrus validator that knows the type can still handle it. _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]
