davsclaus opened a new pull request, #29010: URL: https://github.com/apache/camel/pull/29010
Fixes [CAMEL-26182](https://issues.apache.org/jira/browse/CAMEL-26182). ### 1. sync=false producer lost the body and headers of an InOut exchange `MinaProducer.maybeDisconnectOnDone` read the `CamelMinaCloseSessionWhenComplete` header with `exchange.getOut()` when the exchange is out capable. With `sync=false` no reply is set, so this created an empty out message: the body and headers were gone after the producer. It now reads the header with `exchange.getMessage()`. With `sync=true` the reply is still on the out message, so nothing changes there. ### 2. The consumer wrote a reply also with sync=false `MinaConsumer.ReceiveHandler.messageReceived` wrote the body back whenever it was not null and never looked at `sync`. A client that only sends (TCP or UDP) got its own message echoed. The consumer now writes a reply only with `sync=true`. With `sync=false` the session stays open unless `disconnect=true` or the close-session header says otherwise. In the same block: with no reply the consumer always closed the session and logged at DEBUG, ignoring `disconnectOnNoReply` and `noReplyLogLevel` (both documented as consumer options). It now honours both. The defaults (`true`, `WARN`) keep closing the session. ### 3. A textline consumer wrote a byte[] or stream reply as its toString The producer converts the body to a `String` for `textline=true`, but the consumer passed the reply as it was to the MINA `TextLineEncoder`, which calls `toString()`. A `byte[]` arrived as `[B@...`, a stream as its class name. The consumer now converts the reply to a `String` with the type converter when `textline=true`, as the producer does. ### 4. A byte[] reply did not decode with the default object codec This is the allow-list of the MINA object codec doing its job, not a bug in Camel. MINA's decoder only deserializes the classes that `objectCodecPattern` lists (the list is empty by default; a `String` passes because Java serialization writes it without a class descriptor). For a rejected array the JDK `ObjectInputStream` keeps reading after the `ClassNotFoundException` and fails with `StreamCorruptedException: invalid type code: ...`. With `objectCodecPattern=[B` on the producer the reply decodes. No code change: the component doc now explains this, and the `@BodyTypes` texts say a byte array needs `[B`. The default allow-list is not widened. ### Tests - `MinaSyncFalseTest`: InOut producer with `sync=false` keeps body and header; TCP and UDP consumers with `sync=false` write nothing back (plain sockets). - `MinaConsumerReplyTest`: textline `byte[]` and stream replies, the close-session header, the session staying open without it, `disconnectOnNoReply=false` keeping the session usable for the next request, and a `byte[]` reply with `objectCodecPattern=[B`. Before the fix, 7 of the new tests failed (`null` body, echoed replies over TCP and UDP, `[B@...`, `java.io.ByteArrayInputStream@...`, session closed with `disconnectOnNoReply=false`). The close-session header test and the `objectCodecPattern=[B` test already passed; they guard the behaviour around the change. Full camel-mina suite: 132 tests, 0 failures, 4 skipped (`mvn clean install -Psourcecheck`). ### Docs and generated files - `mina-component.adoc`: replaced the stale warning about `sync=false` with what it does now, and added a section on the reply of the consumer (textline, object codec allow-list, no reply). - `@BodyTypes` of `MinaEndpoint`: `consumerReply` no longer says the body is written back with `sync=false`, and textline accepts any body; `producerOut` with `sync=false` is `unchanged`. Regenerated `mina.json` and copied it and the adoc into `camel-catalog`. - Upgrade guide 4.24: new `camel-mina` section. ### Not changed - The `CamelMinaCloseSessionWhenComplete` lookup in the consumer uses the same `isOutCapable`/`getOut` pattern as the producer did, but the consumer exchange is InOnly (or InOut with the out message already set with `transferExchange`), so it works today and is left as is. - The default object codec allow-list is not changed to accept `[B`, as relaxing a deserialization default needs PMC sign-off. _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]
