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

   Fixes [CAMEL-26140](https://issues.apache.org/jira/browse/CAMEL-26140).
   
   All five bugs in the issue were real and are fixed. For a Map, List or 
object body this follows camel-http and camel-platform-http-vertx: fail with a 
clear message from `BodyFacts`. It does not write the `toString()` form, and it 
does not use Java serialization.
   
   ### 1. A Map, List or object reply was an empty 200
   `UndertowConsumer.sendResponse` called `mandatoryConvertTo(ByteBuffer.class, 
body)`. That fails for such a body. The failure was logged as a WARN, and 
Undertow then ended the exchange with the 200 already set and no body.
   - Now: the consumer answers **500** with an empty body when the reply cannot 
be written and the response has not started. The WARN says what the body is and 
which marshal writes it. Example: `the body is a Map, which is not an HTTP 
response body: marshal it first with the data format to write (such as marshal: 
json, ...)`. The 500 also applies to any other exception while writing the 
reply, which used to end as an empty 200 too.
   
   ### 2. An Integer body was sent as 4 binary bytes
   The consumer reply and the producer request both used the core 
`NIOConverter`, which writes an Integer, Long, Short, Float or Double in binary 
form.
   - Now: a new `UndertowHelper.toByteBuffer(TypeConverter, Object, String)` 
sends a number, boolean, character, enum or CharSequence as its text, in the 
charset that the Content-Type declares (UTF-8 otherwise). These are the values 
that `BodyFacts` treats as "a single value". A boolean or a character used to 
send no body at all.
   
   ### 3. The producer sent a Map, List or object as an empty POST
   `tryConvertTo(ByteBuffer.class, body)` returned null, so the request went 
out with no body and no error.
   - Now: for a POST, PUT or PATCH the exchange fails with an 
`InvalidPayloadException` that says what the body is and which marshal writes 
it. If the Content-Type names a data format, the hint names it too, for example 
`marshal: json` for `application/json`. This is the same message camel-http 
gives.
   - Not changed: for a GET, DELETE or another method, a body that does not 
convert is still left out without an error. A leftover body before a GET is 
common, and camel-http ignores the body of a GET or DELETE by default.
   
   ### 4. The consumer dropped the body of a DELETE and other methods
   `DefaultUndertowHttpBinding.toCamelMessage` read the body only for POST, PUT 
and PATCH.
   - Now: it also reads the body of any other method when the request has a 
body (Content-Length above 0, or a Transfer-Encoding header). A request with no 
body still has a null body.
   
   ### 5. The producer gave an empty byte[] for a 204
   - Now: a 204, a 304, or the response to a HEAD has a null body, as with 
camel-http. A 200 with an empty body is still an empty `byte[]`, as before. In 
streaming mode the connection is closed as usual, because the body is not an 
InputStream.
   
   ### Tests
   - New `UndertowBodyConversionTest` (13 tests): Integer and boolean replies 
as text, Map, List and object replies give 500, the producer sends 42 as `42`, 
the producer fails on a Map or List (and names `marshal: json` for 
`application/json`), a GET with a Map body still works, DELETE with and without 
a body, and a null body for 204 and HEAD. Without the fix, 12 of the 13 fail. 
`testDeleteWithoutBody` guards against a regression.
   - `UndertowSwitchingStatus204Test`: the two 204 producer tests now expect a 
null body instead of `""`, matching `JettySwitchingStatusCode204Test` 
(camel-http).
   - `mvn clean install -Psourcecheck` in camel-undertow: 268 tests, 0 
failures, 1 skipped.
   
   ### Docs
   - `undertow-component.adoc`: a new "Message body" section, also copied into 
the catalog docs.
   - Upgrade guide 4.24: a new section "camel-undertow - the bodies of requests 
and responses". It covers numbers as text, 500 or a failed exchange for a Map, 
List or object body, the DELETE body, and a null body for a 204, 304 or HEAD 
response.
   
   _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