oscerd opened a new pull request, #29080: URL: https://github.com/apache/camel/pull/29080
Fixes [CAMEL-26239](https://issues.apache.org/jira/browse/CAMEL-26239), found while adding the catalog body types (CAMEL-24961). ## 1. A stream body is stored as the stream **Was:** `put` and `putIfAbsent` stored `message.getBody()` as it is. A stream body (an `InputStream`, a `Reader`, or the stream cache that stream caching turns them into) was stored as the stream object: the first `get` could read it, the later ones got an empty stream, and every exchange that got the key shared the same stream object. A backend that serializes its values could not store it at all. **Now:** `put` and `putIfAbsent` read a stream body (`InputStream`, `Reader` or `StreamCache`) and store its bytes, so every `get` gives the whole content as a `byte[]`. Bytes keep binary content as it is, which text would not. A `Reader`, cached or not, is stored as its text in the charset of the exchange (UTF-8 by default); without this, a cached `Reader` would be written in the default charset of the JVM. Every other body (text, bytes, a `Map`, a `List`, a POJO) is still stored as it is. ## Tests `StateStoreStreamBodyTest` (in-memory backend) puts a binary stream that is not valid UTF-8 through a route with stream caching (the producer gets a stream cache), through a route without it (the producer gets the `InputStream`), a stream cache given as the body, a `Reader` with `putIfAbsent`, and a cached and a plain `Reader` with an ISO-8859-1 exchange charset, and checks that three gets in a row each give the whole content as a `byte[]`. It also checks that a later `put` gives the stored bytes as the previous value, and that a `byte[]`, a `List`, a `Map` and text are still stored as the same objects. Revert check: without the fix in `StateStoreProducer`, 7 of the 8 tests fail on an assertion, as the get gives the stored stream object (a `ByteArrayInputStream`, a stream cache or a `Reader`) instead of bytes. The one that passes is `testOtherBodiesAreStoredAsTheyAre`, which guards the bodies that must not change. Module: 32 tests, 0 failures, 0 errors. ## Docs and generated files The `@BodyTypes` of the endpoint say that a stream is read and stored as its bytes and that a `get` then gives a byte array; the component JSON is regenerated and its catalog copy updated. The component doc says the same under Operations, and its catalog copy is updated. The upgrade guide has an entry, as a route that puts a stream now gets a `byte[]` back from `get`. ## Not changed - A `Reader` is stored as bytes too, rather than as text, so that a `get` gives the same type for every stream body. - A file body (`GenericFile`, `File` or `Path`) is still stored as the file reference; the issue does not cover it. - The Cache EIP of camel-core also puts the body into a `KeyValueRepository` as it is, so a stream result is cached as the stream object. That is outside this component and is left for a follow-up. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 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]
