davsclaus opened a new pull request, #28998: URL: https://github.com/apache/camel/pull/28998
Fixes [CAMEL-26172](https://issues.apache.org/jira/browse/CAMEL-26172). ### 1. A stream body sent a truncated, invalid JSON request `SplunkHECProducer.process` wrote the payload with Jackson inside an `EntityTemplate`, so while the request was already being sent. When Jackson failed half way, the exchange failed, but a truncated JSON request had already reached the server. Now the payload is written to a `byte[]` first and sent as a `ByteArrayEntity`. A payload that cannot be written as JSON fails the exchange before any request is made. Side effect: the request has a `Content-Length` instead of a chunked body. ### 2. Bytes were sent as base64, a File as its path `createPayload` put `message.getBody()` in the event as is. Jackson wrote a `byte[]` as base64 and a `java.io.File` as its path. A stream failed (see 1), and the `GenericFile` body of the file consumer failed too (`No serializer found for class FileBinding`). Now a `byte[]`, `InputStream`, `Reader`, `File`, `Path`, `WrappedFile` (file consumer) or `ByteBuffer` body is converted to text with `getMandatoryBody(String.class)` before it goes in the event (with `bodyOnly` and in the default body + headers mode). With `headersOnly` the body is not read, as before. Other bodies (text, Map, List, POJO) are written by Jackson as before. ### Tests New tests in `SplunkHECProducerHttpTest` against a local JDK `HttpServer`: stream body (bodyOnly and with headers), bytes, `File` and `Path`, the file consumer body (via `pollEnrich`), and a payload Jackson cannot write must not reach the server. Five of them failed before the fix (base64, the file path, the `FileBinding` error, the stream failures, and the truncated request arriving at the server). Module: 39 tests, 0 failures (2 skipped manual ITs). ### Docs and generated files - `@BodyTypes` of the endpoint: added the bytes, stream and file carriers, and the description no longer says to convert them first. Catalog JSON regenerated. - Component doc: a short paragraph on bytes, stream and file bodies. Catalog copy updated. - Upgrade guide 4.24: a `camel-splunk-hec` entry, as bytes were sent as base64 before. ### Not changed - Header values are still written by Jackson as is (a `byte[]` header is still base64). The issue is about the body only. A header Jackson cannot write now fails before sending. _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]
