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

   Fixes [CAMEL-26218](https://issues.apache.org/jira/browse/CAMEL-26218), 
found while adding the catalog body types (CAMEL-24961).
   
   ## 1. A body that is not the request type is dropped silently
   
   **Was:** `infer`, `model/ready` and `model/metadata` read the body with 
`getBody(<request>.class)` and merged it into the request only when that gave a 
value. Any other body, such as text, JSON, bytes or a `Map`, was dropped 
without an error and the request was sent without it: `infer` sent a request 
with no inputs, and `model/ready` and `model/metadata` ignored the body.
   
   **Now:** When the body is not empty and does not convert to the request of 
the api, the exchange fails with an `InvalidPayloadException` before anything 
is sent. The message names the expected request type and the api, for example 
`No body available of type: inference.GrpcPredictV2.ModelInferRequest but has 
type: java.lang.String on: Message[...] (the infer api reads a 
ModelInferRequest with the input tensors, or its Builder: build the protobuf 
request before the endpoint)`. It gives the class of the body, never its 
content.
   
   No body, a blank `String` or an empty `byte[]` still sends a request built 
from the options and headers, so a route whose previous step left an empty body 
keeps working with `model/ready` and `model/metadata`. A body that is the 
request or its Builder is sent as before, and `server/ready`, `server/live` and 
`server/metadata` still do not use the body.
   
   `KServeProducer.process` now declares `throws Exception`, as 
`Processor.process` does, to throw the checked `InvalidPayloadException`.
   
   ## Tests
   
   `KServeProducerBodyTest` runs the producer against a local gRPC server with 
a fake `GRPCInferenceService` that records the requests it receives. The server 
uses the grpc-netty-shaded transport the module already depends on, so there is 
no new dependency.
   
   - JSON text, bytes, a `Map`, or the request of another api fails with an 
`InvalidPayloadException` of the request type that names the api, and no 
request reaches the server (8 cases over `infer`, `model/ready` and 
`model/metadata`).
   - `model/ready` with an empty `String`, a blank `String` or an empty 
`byte[]` asks for the model of the options, like no body.
   - A `ModelInferRequest`, its Builder and no body for `infer`, a 
`ModelReadyRequest` and no body for `model/ready`, and a Builder and no body 
for `model/metadata` are sent as before.
   - `server/ready` with a text body still calls the server.
   
   Revert check: with the producer, endpoint and page changes reverted, 8 of 
the 19 new tests fail on their assertions: the 8 bodies that are not the 
request (no exception, the request was sent). The 11 that pass check behaviour 
that does not change: the request, its Builder, no body, the empty bodies and 
the server api.
   
   Module: 20 tests, 0 failures (the 19 new ones and 
`KServeEndpointDoStopTest`).
   
   ## Docs and generated files
   
   - `@BodyTypes`: `model/ready` and `model/metadata` take no body or their 
request (`null`, `pojo`) instead of any body, and the description says that 
another body that is not empty fails and that an empty one counts as no body.
   - The component page says which body the apis read, that another body that 
is not empty fails with an `InvalidPayloadException`, and that a blank `String` 
or an empty `byte[]` counts as no body.
   - Regenerated `kserve.json`, and the catalog copies of the JSON and the page.
   - Upgrade guide entry for 4.24, as a body that was ignored now fails the 
exchange.
   
   ## Not changed
   
   - JSON text and protobuf bytes are not parsed into the request: that would 
be a new feature, and the page and the body types say to build the protobuf 
request before the endpoint.
   - An empty stream is not treated as empty, since telling would mean reading 
it. A stream body that is not the request fails like other bodies; the servlet 
and jetty consumers can leave one for a GET without a Content-Length header 
unless `eagerCheckContentAvailable` is set.
   - The server apis keep ignoring the body, as the issue does not mention them 
and their requests have no fields.
   
   Main only, as the other fixes of the CAMEL-24961 follow-ups.
   
   _Claude Code on behalf of Andrea Cosentino (oscerd)_
   
   🤖 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