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

   Fixes [CAMEL-26144](https://issues.apache.org/jira/browse/CAMEL-26144).
   
   ### 1. Default binding: an unchanged request body fails with "No message 
body writer"
   
   **What was wrong:** with the `Default` binding the consumer body is the 
`MessageContentsList` of the resource method parameters. 
`DefaultCxfRsBinding.populateCxfRsResponseFromExchange` returned the body as 
the response entity, so a route that does not set a reply (e.g. only logs) 
failed with HTTP 500 "No message body writer has been found for class 
org.apache.cxf.message.MessageContentsList".
   
   **What changed:** a `MessageContentsList` reply of one element is now the 
response entity (its element), and an empty one replies with no content (204). 
Two exceptions keep the old behaviour:
   - When the resource method returns a `Collection`, the list is left as is. 
CXF already writes it as that collection (a `GET` of `List<Customer> 
getCustomers()` with an unchanged body replied `200 <Customers></Customers>` 
and still does). Without this check it would become a 204.
   - A `MessageContentsList` of several parameters is left as is. No element is 
the obvious reply.
   
   The `SimpleConsumer` binding is unchanged. It already replies without an 
entity for a `MessageContentsList`. It now calls the new protected 
`doPopulateCxfRsResponseFromExchange` (the old body of the method), so it still 
sees the raw list.
   
   ### 2. HTTP API producer: only the first element of a List body is sent
   
   **What was wrong:** `DefaultCxfRsBinding.bindCamelMessageBodyToRequestBody` 
took `get(0)` of any `List` body, so the other elements (e.g. a JSON array of 
items) were dropped without an error.
   
   **What changed:** a `List` body is now the request entity as a whole. A 
`MessageContentsList` still sends its first element, as before. That is CXF's 
parameter carrier (the body from a `cxfrs` consumer, or a SOAP POJO reply whose 
first element is the return value). Also, an empty `MessageContentsList` now 
sends no body. Before, it failed with an `IndexOutOfBoundsException`. That is a 
small bug on the same line.
   
   ### Tests
   - `DefaultCxfRsBindingTest`: unit tests for the reply (one element, empty, 
several, a plain List), the Simple binding (no entity), and the request body 
(List of several and of one, `MessageContentsList`, empty 
`MessageContentsList`).
   - `CxfRsConsumerUnchangedBodyTest`: a real `cxfrs` consumer whose route does 
not change the body. A `PUT` of a Customer now replies 200 with the Customer 
XML (it was a 500 before). A `GET` of the collection method still replies with 
the empty collection.
   - Both new unit tests and the PUT test failed before the fix (the main code 
was reverted to check this).
   - `camel-cxf-rest`: 56 tests pass with `-Psourcecheck`. 
`camel-cxf-spring-rest`: 111 tests pass.
   
   ### Docs and generated files
   - The `cxfrs-component.adoc` page covers both behaviours. The `@BodyTypes` 
descriptions on `CxfRsEndpoint` were updated, and `cxfrs.json` was regenerated 
and copied to the catalog with the doc.
   - Upgrade guide: a new `camel-cxfrs` entry. Two groups of users are 
affected. First, users with a JSON provider that writes any object: an 
unchanged single-parameter body was written as a one-element array and is now 
the element. Second, HTTP API users who sent a `List` of one element.
   
   ### Not changed
   - An `Object[]` body still sends its first element: it is converted to a 
`MessageContentsList`. The issue is about `List` bodies only.
   
   _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