oscerd opened a new pull request, #29064: URL: https://github.com/apache/camel/pull/29064
Fixes [CAMEL-26217](https://issues.apache.org/jira/browse/CAMEL-26217), found while adding the catalog body types (CAMEL-24961). ## 1. A body that is not the request type is dropped silently **Was:** The producer 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: `predict` then failed on the server with "Missing but required" and no hint about the body, and `model-status` 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: tensorflow.serving.Predict.PredictRequest but has type: java.lang.String on: Message[...] (the predict api reads a PredictRequest 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-status` and `model-metadata`. A body that is the request or its Builder, or an `Input` for `classify` and `regress`, is sent as before. ## 2. model-metadata adds signature_def twice **Was:** `model-metadata` added the `signature_def` metadata field and then merged the `GetModelMetadataRequest` of the body. Merging appends to a repeated field, so a request that named `signature_def` asked for it twice, and a request that named other fields got `signature_def` as well. **Now:** The request of the body is merged first, and `signature_def` is added only when the request names no metadata field. Without a body, or with a request that names no field, the request asks for `signature_def` as before. ## Tests `TensorFlowServingProducerBodyTest` runs the producer against a local gRPC server with fake `ModelService` and `PredictionService` implementations that record the requests they receive. 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 the five apis). - `model-status` with an empty `String`, a blank `String` or an empty `byte[]` asks for the model of the options, like no body. - A `PredictRequest`, its Builder and no body for `predict`, an `Input` for `classify` and `regress`, and no body for `model-status` are sent as before. - `model-metadata` asks for `signature_def` once: without a body, when the request names it, and when the request names no field (keeping the model of the request). Revert check: with the producer, endpoint and page changes reverted, 9 of the 20 new tests fail on their assertions: the 8 bodies that are not the request (no exception, the request was sent) and the request that names `signature_def` (it was asked for twice). The 11 that pass check behaviour that does not change: the request, its Builder, an `Input`, no body and the empty bodies. Module: 21 tests, 0 failures (the 20 new ones and `TensorFlowServingEndpointDoStopTest`). ## Docs and generated files - `@BodyTypes`: `model-status` 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, that an empty one counts as no body, and when `model-metadata` asks for `signature_def`. - The component page says which body each api reads, that another body that is not empty fails with an `InvalidPayloadException`, that a blank `String` or an empty `byte[]` counts as no body, and that `model-metadata` asks for `signature_def` unless the request names its metadata fields. - Regenerated `tensorflow-serving.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 model spec of a request in the body still overrides the options and headers, as the merge did before. 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]
