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

   Fixes [CAMEL-26189](https://issues.apache.org/jira/browse/CAMEL-26189).
   
   ### 1. A body that does not convert to byte[] was silently skipped
   
   **What was wrong:** `JGroupsRaftProducer.process` read the body with 
`getBody(byte[].class)`. For a `Map`, an `Integer` or a POJO this is null, and 
the producer only logged "Body is null, cannot call set method on raftHandle." 
at DEBUG. Nothing was set in the replicated log and the exchange succeeded.
   
   **What changed:** a non-null body is now read with 
`getMandatoryBody(byte[].class)`. A body with no conversion to bytes fails the 
exchange with an `InvalidPayloadException`, for example `No body available of 
type: byte[] but has type: java.lang.Integer`. A null body is still skipped, as 
before.
   
   ### 2. A List body failed with a misleading TypeConversionException
   
   **What was wrong:** the core `ArrayTypeConverter` (a fallback converter) 
tries to copy the List elements into a `byte[]` with `Array.set`, which throws 
`IllegalArgumentException: argument type mismatch` for a String element. The 
registry wraps it in a `TypeConversionException` that says "from type: 
java.lang.String", because 
`CoreTypeConverterRegistry.createTypeConversionException` builds the exception 
from the value prepared for logging (a String), not from the body itself.
   
   **What changed:** with the mandatory conversion of bug 1, the producer now 
fails with an `InvalidPayloadException` that names the body: `No body available 
of type: byte[] but has type: java.util.ArrayList`. The 
`TypeConversionException` is kept as the cause.
   
   **Not changed:** the two core causes (the array converter throws instead of 
returning no conversion, and the "from type" of a `TypeConversionException` is 
always `String` when an exchange is given). Both are in camel-core and affect 
every component, so they are left for a separate core issue.
   
   ### 3. raftId and channelProperties were not endpoint options in the catalog
   
   **What was wrong:** `JGroupsRaftEndpoint` had the fields `raftId`, 
`channelProperties`, `raftHandle` and `stateMachine` with setters, but no 
`@UriParam`. They worked as endpoint query parameters (the tests already use 
`?raftId=A&channelProperties=raftABC.xml`, `?raftHandle=#rh` and 
`?stateMachine=#sm`), but the catalog, the doc and the endpoint DSL listed them 
only as component options.
   
   **What changed:** all four fields have `@UriParam` and a description, with 
the same defaults as the component options (`raft.xml`, `NopStateMachine`). 
`raftHandle` and `stateMachine` are included because they have the same gap on 
the next lines and are used as endpoint options in the tests. `raftId` is not 
required on the endpoint, as it can come from the component.
   
   ### 4. The doc said the producer body must be a byte[]
   
   The doc now says the body is converted to a `byte[]` (such as from text, a 
stream or a file), that a body that cannot be converted fails with an 
`InvalidPayloadException`, and that a null body is skipped. The `@BodyTypes` 
text of the endpoint says the same.
   
   ### Tests
   
   - New `JGroupsRaftProducerBodyTest` (one local node, no leader needed): a 
`Map`, an `Integer`, a POJO and a `List` body fail with an 
`InvalidPayloadException` (the List one names `java.util.ArrayList`); a null 
body is skipped. Without the fix, the Map, Integer and POJO tests failed (the 
exchange succeeded) and the List test failed (a `TypeConversionException`).
   - `JGroupsRaftEndpointTest.shouldHaveRaftOptionsAsEndpointOptions`: the four 
options are endpoint properties. It failed without the fix.
   - `JGroupsRaftProducerTest` also sends a text body and checks it is set.
   - `mvn clean install -Psourcecheck` in the module: 31 tests, all pass.
   
   ### Docs and generated files
   
   - Regenerated the component JSON, the endpoint configurer and URI factory, 
the catalog JSON and doc, and `JGroupsRaftEndpointBuilderFactory` in 
camel-endpointdsl (component options did not change).
   - Upgrade guide 4.24: new `camel-jgroups-raft` entry, because a Map, POJO or 
number body now fails instead of being skipped.
   
   _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