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

   Fixes [CAMEL-26142](https://issues.apache.org/jira/browse/CAMEL-26142).
   
   ### 1. A route ending with a null body sent the request payload back
   
   **What was wrong:** `SpringWebserviceMessage.createBody()` returns the 
payload of the request whenever the body is `null`. So a consumer route that 
set the body to `null` in a processor (`exchange.getMessage().setBody(null)`) 
replied with the request payload. (The `setBody` EIP with a `null` value was 
not affected, as it replaces the message with a `DefaultMessage`.)
   
   **What changed:** `SpringWebserviceMessage` tracks whether the body has been 
set (also to `null`). The body is only created from the request until then. 
`reset()` and `setWebServiceMessage()` clear the flag. This is the same idea as 
`JmsMessage.setBody(null)`.
   
   ### 2. A reply that did not convert to Source gave an empty SOAP body
   
   **What was wrong:** `SpringWebserviceConsumer` used the non-mandatory 
`getBody(Source.class)`. For a `Map` (or a raw `InputStream`, see 3) it was 
`null`, and the client got an empty SOAP body with no fault and no log.
   
   **What changed:** a non-null reply body is converted with 
`getMandatoryBody(Source.class)`, so it ends as a SOAP fault with the 
conversion error. A `null` body still gives an empty SOAP body.
   
   ### 3. The producer rejected a File body, and an InputStream without stream 
caching
   
   **What was wrong:** there is no `File` to `Source` or `InputStream` to 
`Source` type converter (only to `StreamSource`, `SAXSource` etc.), so 
`getMandatoryBody(Source.class)` failed with `InvalidPayloadException`. With 
stream caching on, an `InputStream` became a `StreamCache`, which converts.
   
   **What changed:** a new `SpringWebserviceHelper.toSource(Message)` wraps a 
`File` or an `InputStream` that is not a `StreamCache` in a `StreamSource`, and 
otherwise uses `getMandatoryBody(Source.class)`. Both the producer and the 
consumer reply use it, so an `InputStream` reply is now sent as XML too.
   
   ### Tests
   
   - New `ConsumerReplyBodyTest` (spring-ws `MockWebServiceClient`): null body 
from a processor, null body from the `setBody` EIP, a `Map` reply gives a 
fault, a `ByteArrayInputStream` reply is sent.
   - `ProducerLocalRouteTest`: a `File` body, and a `ByteArrayInputStream` body 
on a route with `streamCache="false"`.
   - Without the fix in `src/main`, 5 of these fail (null from a processor, 
Map, InputStream reply, File, InputStream producer); the `setBody` EIP test 
passed before and guards that case.
   - `mvn clean install -Psourcecheck` in the module: 109 tests, 0 failures (17 
skipped, as on main).
   
   ### Docs
   
   - `spring-ws-component.adoc`: which bodies the producer sends, and what a 
null or non-XML reply body gives. The catalog copy is regenerated.
   - Upgrade guide 4.24: a `camel-spring-ws` entry, as a null reply no longer 
echoes the request and a non-XML reply now gives a fault instead of an empty 
body.
   
   ### Not changed
   
   - A `GenericFile` body from a `file:` consumer still does not convert to 
`Source`: `GenericFileConverter` looks up a `File` to `Source` converter, which 
does not exist. Not part of this issue; I left it for now.
   - `SpringWebserviceMessage.newInstance()` passes the request message along, 
so an OUT message created with `exchange.getOut()` still creates its body from 
the request until a body is set. Unchanged behaviour.
   
   _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