[Java] How to send trailing metadata in sucess scenarios

31 views
Skip to first unread message

grp...@gmail.com

unread,
Sep 11, 2017, 11:39:26 PM9/11/17
to grpc.io
Wanted to know how to send trailing metadata (headers) in case of success scenarios. I'm aware of how to send it in cases of exceptions but couldn't find a way to do it in case of success. Although there seems to be a way to do in python. 

Carl Mastrangelo

unread,
Sep 12, 2017, 7:55:48 PM9/12/17
to grpc.io
In java there are two ways:

The first and more common way is to install a ServerInterceptor, which has access to the Metadata (a.k.a. headers).   Typically the interceptor will create a ForwardingServerCall, which will add the desired headers in the close() method.  Since the location of the code that wants to add the header is usually far away from where the interceptor is installed, the interceptor can read the headers out of the Context.  When handling an RPC, add the custom headers into the context and the interceptor will apply them.

The second way is more complicated, and that is to use the ServerCall object directly.  This is useful if you want more advanced control over the call.  Few people use this. 
Reply all
Reply to author
Forward
0 new messages