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

   Fixes [CAMEL-26177](https://issues.apache.org/jira/browse/CAMEL-26177).
   
   ### 1. post and put sent bytes as base64 and a file as its path, and a 
stream failed
   
   `Dhis2Producer.findMethod` passed the body as is as the `resource` argument, 
and the DHIS2 client serializes any non-`String` resource with Jackson. So a 
`byte[]` of JSON went out as a base64 JSON string, a `java.io.File` as its path 
string, and an `InputStream` failed with `No serializer found for class 
java.io.ByteArrayInputStream`.
   
   Now a resource that is bytes, a stream, a `Reader`, a `File`, a `Path`, a 
`WrappedFile` (file consumer) or a `StreamCache` is converted to `String` with 
the Camel type converter (the exchange charset applies) before the call, so its 
JSON is sent as it is. This applies to the resource from the body, from 
`inBody=resource` and from the `CamelDhis2.resource` header. A `Map`, a `List` 
and a POJO are still serialized by Jackson.
   
   ### 2. A leftover body was sent as the payload of delete/resource
   
   `findMethod` took the body as `resource` for every call, so 
`delete/resource` sent any body left by an earlier step as its DELETE payload. 
Now only `post` and `put` take the body. `delete` sends a resource only when 
given by `inBody=resource` or the `CamelDhis2.resource` header (DHIS2 uses a 
DELETE body to remove collection items, so that stays possible). `get` and 
`resourceTables` no longer get the body as an unused `resource` argument.
   
   ### 3. The get/collection consumer sent one message with an Iterator body
   
   `Dhis2Get.collection` returns an `Iterator<Dhis2Resource>`, and 
`ApiConsumerHelper.getResultsProcessed` splits Lists, Iterables and arrays but 
not an Iterator. `Dhis2Consumer.splitResult` now wraps the Iterator in an 
`Iterable`, so the consumer sends one message per `Dhis2Resource`. The pages 
are still read lazily. The fix stays in camel-dhis2 instead of 
`ApiConsumerHelper` in camel-support, so other API components do not change.
   
   ### Tests
   
   New `Dhis2BodyTest` runs a JDK `HttpServer` as the DHIS2 Web API and records 
the requests: post with text, bytes and a Map; put with a stream and a file; 
delete with a leftover body, with `inBody=resource` and with the header; and 
the `get/collection` consumer. 6 of the 9 tests failed before the fix (bytes, 
stream, file, leftover delete body, inBody delete, consumer); text, Map and 
header-delete passed before and after. `mvn clean install -Psourcecheck` in 
camel-dhis2-component passes.
   
   ### Docs and generated files
   
   - `@BodyTypes` of the endpoint updated (producer in: bytes, stream, file; 
delete only via inBody/header; consumer out of `get/collection`: map) and 
regenerated; the catalog `dhis2.json` and `dhis2-component.adoc` copied.
   - New "Message body" section in `dhis2-component.adoc`.
   - Upgrade guide 4.24: new `camel-dhis2` section (delete no longer sends the 
body; bytes/stream/file; one message per item of the collection consumer).
   
   ### Not changed
   
   - No `splitResult` option was added: `Dhis2Configuration` does not extend 
`AbstractApiConfiguration` (only google-sheets has that option), and the other 
API components also always split a list result. A route that did 
`.split().body()` after the `get/collection` consumer must drop the split (in 
the upgrade guide).
   - The `get/collection` producer still returns the `Iterator` (the documented 
examples split 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]

Reply via email to