davsclaus opened a new pull request, #29012: URL: https://github.com/apache/camel/pull/29012
Fixes [CAMEL-26187](https://issues.apache.org/jira/browse/CAMEL-26187). ### What was wrong The `grpc` consumer passed the body at the end of the route to `responseObserver.onNext` as is. When the route left the request unchanged, the `PingRequest` was serialized and the client decoded the bytes as a `PongResponse`: no error, a response with wrong field values. A body of another class (text, bytes, a Map) failed in the marshaller and the client saw `CANCELLED` with no hint why. ### What changed - `GrpcMethodHandler` looks up the response message type of the called method once per method: the generic type of the response `StreamObserver` parameter of the method on the service `ImplBase` class. - Each reply message (each element of a `List` reply) is converted to that type with the Camel type converter. A message that is already of that type is sent as is. - When a message cannot be converted, nothing is sent and the call ends with an `INTERNAL` status error. The description follows `muteException` like other failures (muted by default). A WARN log names the expected and the actual type. - The whole reply is checked before the first message is sent, so a server streaming reply does not send part of a List and then fail. - This applies to unary and server streaming calls, and to the `AGGREGATION` and `PROPAGATION` consumer strategies. A reply without a body still sends an empty message, as before. - With `routeControlledStreamObserver=true` (and `DELEGATION`) the route sends the responses itself; that path is not changed. - If the response type cannot be found (for example a custom `bindableServiceFactory` with no `ImplBase` class), the body is sent as before. ### Tests New `GrpcConsumerReplyTypeTest` (10 tests) with an embedded gRPC server on localhost: - unchanged request, text reply, muted description, List with one wrong element (server streaming), AGGREGATION and PROPAGATION with the unchanged request: an `INTERNAL` error naming both types; - a POJO with a type converter to `PongResponse`, for unary, server streaming and PROPAGATION: converted and sent; - no body: an empty message, as before. 9 of the 10 failed before the fix (the no-body test is a guard for the existing behaviour). The module suite passes: 64 tests, with `-Psourcecheck`. ### Docs and generated files - New "gRPC consumer reply" section in `grpc-component.adoc`. - The `consumerReply` `@BodyTypes` text now says that another type is converted or ends the call with an INTERNAL error; `grpc.json` and the catalog copies regenerated. - Upgrade guide 4.24 entry under `camel-grpc`: a route that relied on the body being sent as is now gets an error. _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]
