Claus Ibsen created CAMEL-26140:
-----------------------------------

             Summary: camel-undertow - a Map, List or POJO reply is an empty 
200 and the producer sends it as an empty POST, and an Integer body is sent as 
4 binary bytes
                 Key: CAMEL-26140
                 URL: https://issues.apache.org/jira/browse/CAMEL-26140
             Project: Camel
          Issue Type: Bug
          Components: camel-undertow
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of undertow (CAMEL-24961, PR #28395).

h4. 1. A Map, List or POJO reply is an empty 200

{{UndertowConsumer}} (main 2a465aa4814c, line 298) converts the reply with 
{{mandatoryConvertTo(ByteBuffer.class, body)}}; for a Map, List or POJO this 
fails, the failure is logged as a WARN and the client gets a 200 with an empty 
body. Checked on 4.24.0-SNAPSHOT with a java.net.http client against the 
undertow consumer.

Proposed: write such a body as its String form, or reply 500 instead of an 
empty 200.

h4. 2. An Integer body is sent as 4 binary bytes

Both the consumer reply (UndertowConsumer line 298) and the producer request 
({{UndertowProducer}} line 176) convert the body to a {{ByteBuffer}}, and the 
core converter turns an Integer into its 4-byte binary form, so 
{{setBody(constant(42))}} sends {{00 00 00 2A}} instead of {{42}}. Checked on 
4.24.0-SNAPSHOT with the undertow consumer and producer.

Proposed: convert numbers (and other non-binary values) through String before 
the {{ByteBuffer}}.

h4. 3. The producer sends a Map, List or POJO as an empty POST

{{UndertowProducer}} (line 176) uses {{tryConvertTo(ByteBuffer.class, body)}}; 
for a Map, List or POJO this gives null and the request is sent with no body 
and no error. Checked on 4.24.0-SNAPSHOT with the undertow producer over HTTP.

Proposed: fail the exchange when a non-null body cannot be converted.

h4. 4. The consumer drops the body of DELETE and other methods

{{DefaultUndertowHttpBinding.toCamelMessage}} (line 154) reads the request body 
only for POST, PUT and PATCH and sets null otherwise (line 163), so a DELETE 
(or OPTIONS, or a custom method) with a body reaches the route with no body. 
Checked on 4.24.0-SNAPSHOT with a java.net.http client against the undertow 
consumer.

Proposed: read the body for any method when the request has one (Content-Length 
> 0 or chunked).

h4. 5. The producer gives an empty byte[] for a 204 response

{{DefaultUndertowHttpBinding.toCamelMessage(ClientExchange, Exchange)}} (line 
190) always sets {{readFromChannel(source)}}, so a 204 (or any response with no 
content) becomes an empty {{byte[]}} instead of null. Checked on 
4.24.0-SNAPSHOT with the undertow producer over HTTP.

Proposed: set a null body when the response has no content.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to