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

   Fixes [CAMEL-26269](https://issues.apache.org/jira/browse/CAMEL-26269), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. A Map or POJO body was published as its toString
   
   **Was:** `publishAsTextMessage` and `publishAsTemplatedMessage` published 
`getBody(String.class)`. A Map went out as `{orderId=1, status=shipped}`, a 
List as `[monitors, keyboards]` and a POJO as its `toString()`, without an 
error.
   
   **Now:** a `Map` or a `Collection` is published as JSON, written with the 
Jackson the SDK already brings. Another object that is not a payload is 
published as JSON when Jackson writes it as an object or an array (a POJO, an 
array). Text, bytes, a stream, a file and a single value such as a number, an 
enum or a UUID are still read as text with the type converter. So is an object 
that Jackson cannot serialize, such as one without properties. A Map or a List 
that cannot be written as JSON fails with an `IllegalArgumentException` ("The 
... body cannot be published as JSON: convert it to text first"), and nothing 
is published. `publishAsTemplatedMessage` can still have no body. The rule is 
the same as in the parallel CAMEL-26248 fix (azure-key-vault `createSecret`).
   
   ## 2. The message id property had a typo
   
   **Was:** the id of the published message was only in 
`SmnProperties.SERVICE_MESSAGE_ID`, `CamelHwCloudSmnMesssageId` (three s).
   
   **Now:** the new `SmnProperties.MESSAGE_ID`, `CamelHwCloudSmnMessageId`, 
holds the id. `SERVICE_MESSAGE_ID` is kept and still set to the same id, but is 
marked `@Deprecated(since = "4.24")`, with a javadoc that points to 
`MESSAGE_ID`. Routes that read either name keep working.
   
   ## Tests
   
   - New `PublishMessageBodyTest` (13 tests) with a recording `SmnClient` set 
on the endpoint. It covers a String, byte[] and a stream (each with a non-ASCII 
character), a File, a Map, a List, a POJO (a record), a Map with 
`publishAsTemplatedMessage`, a Map that Jackson cannot write, a UUID, no body 
with a template, and both message id properties with the request id.
   - With the `src/main` changes reverted, 6 of the 13 new tests fail: the Map, 
List, POJO and templated Map are published as their `toString()`, the Map that 
Jackson cannot write is published instead of failing, and 
`CamelHwCloudSmnMessageId` is null. The 7 that pass behave as before: the 
String, byte[], stream, File and UUID bodies, no body with a template, and the 
deprecated `CamelHwCloudSmnMesssageId` property.
   - The tests read the new property by its name, not by the new constant, so 
the revert check compiles. The existing tests still read 
`SmnProperties.SERVICE_MESSAGE_ID` and still pass.
   - Module tests: 27 run, 0 failures, 4 skipped (the functional tests that 
need a real SMN account).
   
   ## Docs and generated files
   
   - Component doc: the table of the properties the producer sets lists 
`CamelHwCloudSmnMessageId`, and lists `CamelHwCloudSmnMesssageId` as 
deprecated. A new "Message body" section says what is published for each body.
   - `@BodyTypes`: `producerIn` adds map, list and pojo (also for 
`publishAsTemplatedMessage`) and says they are published as JSON. `producerOut` 
names `CamelHwCloudSmnMessageId` and the deprecated property. The regenerated 
`hwcloud-smn.json` and the doc are copied to the catalog.
   - Upgrade guide entry for 4.24: JSON for a Map, a List or a POJO, and the 
move to `CamelHwCloudSmnMessageId`.
   
   ## Not changed
   
   - No `jackson-databind` dependency is added to the pom. It comes with 
`huaweicloud-sdk-core` (compile scope), and the module already declares 
`jackson-core`. **Open question:** declare `jackson-databind` explicitly?
   - An object that Jackson cannot serialize (no properties, `java.time` values 
without the JSR-310 module) is still published as its text, as before, rather 
than failing.
   - When to remove `SERVICE_MESSAGE_ID` / `CamelHwCloudSmnMesssageId` is left 
to the maintainers.
   
   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]

Reply via email to