davsclaus opened a new pull request, #28920: URL: https://github.com/apache/camel/pull/28920
Fixes [CAMEL-26143](https://issues.apache.org/jira/browse/CAMEL-26143). All four bugs of the issue are fixed, in `camel-cxf-soap` only. ### 1. A byte[] reply in POJO (and CXF_MESSAGE) mode was a ClassCastException fault `DefaultCxfBinding.populateOutBody` checked `outBody.getClass().isArray()` and cast to `Object[]`, so a `byte[]` reply gave the SOAP fault `class [B cannot be cast to class [Ljava.lang.Object`. It now checks `outBody instanceof Object[]`; any other value, a primitive array included, is wrapped as one value. ### 2. The POJO producer split a body that is not a List into several parameters `CxfProducer.getParams` turned any body that is not a `List` or an `Object[]` into parameters with `getBody(Iterator.class)`: `"Hello,World"` became 2 parameters, a `byte[]` one parameter per byte, and the call failed with "Get the wrong parameter size". Now a `Collection` (a `List` as before, or another collection) or an `Object[]` holds the parameters, and any other body (`String`, `byte[]`, `Number`, a POJO, a `Map`) is the one parameter. ### 3. CXF_MESSAGE sent an empty envelope for a String, byte[], stream or Document The producer (`CxfProducer.getParams`) and the consumer reply (`DefaultCxfBinding.getBodyFromCamel`) passed the body as it is, and CXF's `MessageModeOutInterceptor` only reads a `SOAPMessage` or a `Source`; anything else became an empty envelope, with no error. A body that is not a `SOAPMessage` or a `Source` is now converted to a `DOMSource` (the existing camel-xml-jaxp converters for text, bytes, streams, files and DOM nodes), and the exchange fails when it cannot be converted. On the consumer side a `List` or `Object[]` reply is still passed as it is (its first element is the message), as before. The issue proposed converting to `SOAPMessage`. I used `Source` instead: Camel has no converter to `SOAPMessage`, and CXF builds the `SOAPMessage` from a `Source` with the factory of the SOAP version of the endpoint, so SOAP 1.2 endpoints work too. It is also what the non-SOAP (XML) binding of `CXF_MESSAGE` expects. ### 4. PAYLOAD and RAW replies that did not convert gave an empty response `getBodyFromCamel` used the non-mandatory `getBody(CxfPayload.class)` / `getBody(InputStream.class)`, so a reply such as a `Map` gave an empty `soap:Body` (PAYLOAD) or an empty response (RAW). A non-null reply that cannot be converted now throws `InvalidPayloadRuntimeException`, which the client gets as a SOAP fault. A `null` reply is unchanged (it still goes through the `jaxws.provider.interpretNullAsOneway` handling). `getBodyFromCamel` keeps its public signature. ### Tests New `CxfBodyTypesTest` (with the `BodyTypeService` test interface) in `camel-cxf-soap`, 9 tests: byte[] reply from a POJO consumer, POJO producer with a String with a comma, with a byte[], and with a List, CXF_MESSAGE producer with a String envelope and with a body that does not convert, CXF_MESSAGE consumer replying a stream envelope, and PAYLOAD and RAW consumers replying a Map. With the fix stashed, 8 of them fail (the List one is a regression guard and passes before and after). `mvn -Psourcecheck install` in `camel-cxf-soap`: 181 tests, 0 failures (1 skipped). `camel-cxf-spring-soap`: 157 tests pass; `CxfEndpointBeansRouterTest` hung once in the full run (a POJO call with a `List` body to an address with no server, a path this PR does not change; it looks like the CAMEL-26468 hang) and passes on its own (4 tests). `CxfProducerRouterTest.testCannotSendRequest` in `camel-cxf-soap` hung the same way once and passed on the rerun. ### Docs and generated files - The `@BodyTypes` of `CxfEndpoint` described the old behaviour ("split like the split EIP", "sends an empty envelope"); updated, and the CXF_MESSAGE carriers now include text, bytes and stream. The generated `cxf.json` is regenerated and copied to `camel-catalog`. - `cxf-component.adoc`: one paragraph on the POJO producer parameters, one on the CXF_MESSAGE bodies. - Upgrade guide 4.24: a `camel-cxf` entry, since a route that relied on a comma-separated String giving several parameters must now send a `List`, and PAYLOAD/RAW replies that do not convert are now a fault. ### Not changed - `camel-cxfrs` (CAMEL-26144 covers it). - A body that is an `Iterator` or an `Iterable` that is not a `Collection` is now one parameter in POJO mode (it was iterated before); I kept "iterate only collections" as the issue proposed. The upgrade guide says so ("or another iterable value"). _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]
