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

   Fixes [CAMEL-26259](https://issues.apache.org/jira/browse/CAMEL-26259), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. Binary bodies were sent as text
   
   **Was:** `sendMessage` and `publishMessage` set the body with 
`setMessageBody(String)`, after `MNSUtils.resolveMessageBody` converted any 
body that is not a String to a String. A `byte[]` or a stream went out as its 
UTF-8 text, so bytes that are not UTF-8 (such as 0xff) became U+FFFD, and a 
binary file from a file consumer failed with a `TypeConversionException` 
(`MalformedInputException`).
   
   **Now:** a String is still sent with `setMessageBody(String)`. Any other 
body is converted to `byte[]` with the type converter and sent with 
`setMessageBody(byte[])`, so `byte[]`, `InputStream`, `File` and `GenericFile` 
keep their bytes. A body with no bytes, such as a `Map` or a POJO, is still 
sent as its `toString()`, as the docs say, and no body still fails.
   
   The consumer read the body with the SDK's `getMessageBody()`, which decodes 
it as UTF-8, so the bytes the producer now sends could not be read back by a 
Camel consumer. It now takes `getMessageBodyAsBytes()` and gives a String when 
the bytes are UTF-8 text (as before) and the `byte[]` otherwise. Both send 
paths keep the Base64 encoding of the SDK, so the bytes on the wire for a 
String body are the same as before.
   
   ## 2. receiveMessage was offered but did not work
   
   **Was:** `receiveMessage` was a value of the `operation` option and listed 
in the docs as the consumer operation, but the producer threw 
`UnsupportedOperationException: Unsupported operation: receiveMessage`, and the 
consumer never reads the option.
   
   **Now:** `receiveMessage` is removed from the values of the `operation` 
option. The option is shared by the producer and the consumer (no label), but 
only the producer uses it, so the consumer loses nothing; its description now 
says so. The docs list the three producer operations and say that the consumer 
receives the messages of the queue. A producer with `operation=receiveMessage` 
(set by a route written for 4.23) fails with `receiveMessage is not a producer 
operation: the consumer receives the messages of the queue`. The constant 
`MNSOperations.RECEIVE_MESSAGE` stays.
   
   ## 3. The message id and MD5 were set as exchange properties
   
   **Was:** `MNSHeaders.MESSAGE_ID` and `MESSAGE_BODY_MD5` are `common` 
headers, and the consumer sets them as headers, but `sendMessage` and 
`publishMessage` set them only as exchange properties.
   
   **Now:** both operations set them as headers. They are also still set as 
exchange properties, so routes written for 4.23 keep working. The request id 
stays an exchange property (`MNSProperties.REQUEST_ID`, not a documented 
header).
   
   ## Tests
   
   - `MNSProducerBodyTest` (9 tests): String, `byte[]` with 0xff/0xfe/0x80, 
`InputStream`, `File` and the `GenericFile` of a file consumer sent to a queue, 
`byte[]` and String published to a topic, a `Map` sent as its text, and no body 
failing.
   - `MNSConsumerBodyTest` (3 tests): a binary message is given as `byte[]`, a 
text message as a String, and a fake queue (the mocked `putMessage` feeds 
`popMessage`) carries a `byte[]` and a String from the producer to the consumer 
unchanged.
   - `MNSProducerResponseHeadersTest` (3 tests): the message id and MD5 headers 
after `sendMessage` and `publishMessage` (and the properties as before), and 
the headers of a consumed message replaced after a send.
   - `MNSReceiveMessageOperationTest` (2 tests): the `operation` enum of the 
generated component JSON, and the message of a producer asked to receive.
   - Revert check (the `src/main` changes taken out, the module rebuilt so the 
JSON is regenerated): 12 of the 17 new tests fail, all on the bug (the U+FFFD 
bytes, a String body where bytes are expected, null headers, `receiveMessage` 
in the enum, the old exception message, and the `GenericFile` test, whose send 
fails with the `TypeConversionException`). The 5 that pass are the String send 
and publish, the `Map` body, no body, and the consumer's text message.
   - Module: 24 tests, 0 failures.
   
   ## Docs and generated files
   
   - Component doc: the producer operations (without `receiveMessage`), a new 
"Message body" section for the producer and the consumer, and the headers and 
exchange properties the producer sets.
   - Body types: `consumerOut` is text or bytes, `producerIn` says that bytes, 
streams and files are sent as their bytes, `producerOut` says that the message 
id and MD5 are headers.
   - The regenerated `alibaba-mns.json` (body types, `operation` enum and 
description) and the doc copied into `camel-catalog`. The `operation` enum and 
description change the endpoint DSL.
   - Upgrade guide entry for 4.24: binary bodies on the producer and the 
consumer, the new headers, and `receiveMessage` removed from the operation 
values.
   
   ## Not changed
   
   - `receiveMessage` was removed rather than implemented in the producer. A 
producer receive would be a new feature, and its receipt handle header would 
replace the one an MNS consumer of the same route deletes its message with on 
completion. **Open question:** deprecate `MNSOperations.RECEIVE_MESSAGE` and 
`MNSEndpoint.resolveConsumerOperation()` (which nothing calls), or implement a 
producer receive later?
   - A `Map` or a POJO is still sent as its `toString()`, as the docs and the 
body types said; the alibaba-fc and alibaba-kms fixes (CAMEL-26257, 
CAMEL-26258) make such a body fail with `InvalidPayloadException` instead. 
**Open question:** do the same here? A number body would then fail too, unless 
it converts to bytes.
   - The consumer gives a String or a `byte[]` depending on the content, rather 
than always a `byte[]`, so text consumers keep their String body. A route that 
needs the bytes of any message can use `getBody(byte[].class)`, which gives the 
bytes of the message in both cases (UTF-8 is the default charset of Camel).
   - The `CamelAlibabaMnsMessageId` and `CamelAlibabaMnsMessageBodyMd5` 
exchange properties are kept for compatibility; they could be dropped in a 
later release.
   
   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