I responded to your question on Gitter <https://gitter.im/grpc/grpc?at=6135c52799b7d97528f4d46b>. I said:
I don't think I understand. You are wanting to get CUSTOM_HEADER_KEY's > "customRespondValue" within sendPing()? It is really weird that the service would want to read response headers. So I didn't think I understood your objective. On Sun, Sep 5, 2021 at 1:08 PM Ashish Srivastava <aksrivastav...@gmail.com> wrote: > Hi Team, > i am very new in GRPC. I have created a service and i want to get the > header in my service. I have added the server intercepter but not able to > get my header in below service. > > Can any one help ? > > @Override > public void sendPing(Ping pingRequest, StreamObserver<Pong> > pongResponseObserver){ > Pong pong= null; > try { > pong = createPongResponse(pingRequest); > } catch (ServiceException e) { > logger.log(Level.WARNING,"Error in PingPong Service"); > Metadata metadata = trailersFromThrowable(e); > pongResponseObserver.onError(FAILED_PRECONDITION > .asRuntimeException(metadata)); > } > pongResponseObserver.onNext(pong); > pongResponseObserver.onCompleted(); > } > > > in metadata i am passing below json and in debugging mode it's visible in > interceptor > { > "userId":"srivastava" > } > > Interceptor code: > > public class HeaderServerInterceptor implements ServerInterceptor { > > private static final Logger logger = Logger.getLogger > (HeaderServerInterceptor.class.getName()); > > @VisibleForTesting > static final Metadata.Key<String> CUSTOM_HEADER_KEY = > Metadata.Key.of("custom_server_header_key", Metadata. > ASCII_STRING_MARSHALLER); > > @Override > public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( > ServerCall<ReqT, RespT> call, > final Metadata requestHeaders, > ServerCallHandler<ReqT, RespT> next) { > logger.log(Level.WARNING,"header received from client:" + requestHeaders); > return next.startCall(new > ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) { > @Override > public void sendHeaders(Metadata responseHeaders) { > responseHeaders.put(CUSTOM_HEADER_KEY, "customRespondValue"); > super.sendHeaders(responseHeaders); > } > }, requestHeaders); > } > } > > > > -- > 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 grpc-io+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/grpc-io/0378f968-49b8-4122-806b-6f449097f26an%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/0378f968-49b8-4122-806b-6f449097f26an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 grpc-io+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oNi8G8NjZ2VGv8_N04xHcL%2B6Osc2TosRSx5ZKGF4aipHQ%40mail.gmail.com.
smime.p7s
Description: S/MIME Cryptographic Signature