I am able to do it now with below snippet.
*Interceptor:*
public class ContextInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
String id = headers.get(METADATA_KEY);
Context ctx = Context.current().withValue(CONTEXT_KEY, id);
return Contexts.interceptCall(ctx, call, headers, next);
}
}
*In gRpc service:*
public void sayHello(HelloRequest request, StreamObserver<HelloReply>
responseObserver) {
HelloReply reply = HelloReply.newBuilder()
.setMessage("name = " + request.getName() + ", id = " +
Keys.CONTEXT_KEY.get())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
Thanks,
Mahesh
On Thu, Apr 5, 2018 at 10:58 PM, 'Carl Mastrangelo' via grpc.io <
[email protected]> wrote:
> Can you give a snippet of code showing what you are trying to do but can't?
>
> On Tuesday, April 3, 2018 at 9:51:13 AM UTC-7, Mahesh Kanote wrote:
>>
>> I wanted to access custom headers sent by client as meta data. I am able
>> to do it using context object in server interceptor.
>>
>> On Tue, 3 Apr 2018, 22:12 'Carl Mastrangelo' via grpc.io, <
>> [email protected]> wrote:
>>
>>> gRPC Java does not expose all the headers, because some of them are gRPC
>>> specific. What headers did you want to access?
>>>
>>> On Saturday, March 31, 2018 at 4:15:21 AM UTC-7, Mahesh Kanote wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have question about getting MetaData in grpc service method. By
>>>> Implementing io.grpc.ServerInterceptor its possible to get reference of
>>>> MetaData sent by client. But, is there any way we can get reference to
>>>> MetaData object in grpc service method? Something like HttpServletRequest
>>>> and HttpServletResponse in case of RestControllers.
>>>>
>>>> Thanks,
>>>> Mahesh
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "grpc.io" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/grpc-io.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/grpc-io/92935121-afc4-4e5f-beda-e945b75c78c9%40googlegroups.com
>>> <https://groups.google.com/d/msgid/grpc-io/92935121-afc4-4e5f-beda-e945b75c78c9%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/grpc-io/598963a1-2a16-4ec6-a57a-0462acaf62c9%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/598963a1-2a16-4ec6-a57a-0462acaf62c9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
Thanks,
Mahesh
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/CAFgyg%3DBB-1DUitbt5Lfd%3Db9EQN4Z-vmTjQZsXjB%2BB9%2BtnM4JtA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.