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

   Fixes [CAMEL-26515](https://issues.apache.org/jira/browse/CAMEL-26515). 
Follow-up of #29012 (CAMEL-26187).
   
   ### What was wrong
   
   Since #29012 the `grpc` consumer converts its reply to the response type of 
the called method, or fails the call with `INTERNAL`. With 
`routeControlledStreamObserver=true` the consumer sends nothing: the route 
replies through a producer with `toRouteControlledStreamObserver=true`. That 
producer called `onNext(body)` with the body as is, because it did not know the 
response type. A route that left the `PingRequest` unchanged sent it to the 
client, which decoded the bytes as a `PongResponse` with wrong field values and 
no error. A POJO with a type converter to the response type, or a `List` body, 
failed in the marshaller.
   
   ### What changed
   
   - New exchange property `GrpcConstants.GRPC_RESPONSE_TYPE` 
(`grpcResponseType`), next to `grpcResponseObserver`. The consumer sets it to 
the response message type of the method, for unary and server streaming calls 
and for each event of the `DELEGATION` strategy (`onNext`, `onError`, 
`onCompleted`). It is copied to the reply exchanges with 
`inheritExchangePropertiesForReplies=true`, like the observer.
   - The `toRouteControlledStreamObserver` producer converts the `onNext` body 
with the same code as the consumer (`GrpcMethodHandler.toResponses`, split out 
of `sendResponses`): each element of a `List` body, or the body itself, 
converted to the response type.
   - When a message does not convert, nothing is sent, the call ends with an 
`INTERNAL` status error, and the producer throws the 
`IllegalArgumentException`, so the exchange fails and the route does not go on 
to `onCompleted` on a closed call.
   - The error description follows `muteException` of the producer endpoint 
(muted by default).
   - When the property is not on the exchange (unknown response type, or an 
exchange that did not come from the consumer), the body is sent as before.
   
   ### Tests
   
   New `GrpcRouteControlledReplyTypeTest` (6 tests) with an in-process gRPC 
server on localhost, using the routes and the `Pong` type converter of 
`GrpcConsumerReplyTypeTest`:
   - unary: the unchanged request gives an `INTERNAL` error naming both types; 
muted by default; a POJO is converted;
   - server streaming: a `List` body sends each message;
   - `DELEGATION` bidirectional streaming: the unchanged request gives the 
error, a converted reply is sent and the call completes.
   
   All 6 failed before the fix. The module suite passes: 70 tests, with 
`-Psourcecheck`.
   
   ### Docs and generated files
   
   - The "gRPC consumer reply" section of `grpc-component.adoc` now describes 
the route-controlled path; catalog copy updated.
   - The 4.24 upgrade guide entry for `camel-grpc` (from #29012) now also 
covers the `toRouteControlledStreamObserver` producer.
   - No option, header or `@BodyTypes` change, so no other generated files.
   
   ### Not changed
   
   - Calls on the `StreamObserver` from the `grpcResponseObserver` property in 
the route's own code (a processor) are not checked: Camel does not see them.
   - The producer still fails with a `NullPointerException` when the 
`CamelGrpcEventType` header is missing (for example a unary route-controlled 
route that calls the producer directly). The documented setups always set it. 
Whether a missing header should mean `onNext` or give a clear error is left 
open.
   
   _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