INVALID_ARGUMENT: Failed to parse headers when adding a ServerInterceptor

Viewed 26

I have a Java gRPC service which is working in production already. I am trying to add a ServerInterceptor to add tracing and logging context to it, but when I add the interceptor, the tests fail with the following error.

io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Failed to parse headers.

    at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:271)
    at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:252)
    at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:165)

I have tried removing the custom code and just adding barebones, but still the same, so I am convinced that it's not my tracing/logging code, but the way I am creating the interceptor. Any idea what can be improved here?

Here's the interceptor I have created (the bare bones, without the custom code)

public class ObservableServerInterceptor implements ServerInterceptor {

  @Override
  public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
      ServerCall<ReqT, RespT> serverCall,
      Metadata metadata,
      ServerCallHandler<ReqT, RespT> serverCallHandler) {

    return serverCallHandler.startCall(serverCall, metadata);
  }
}

And here's how I am adding it

final GrpcServer grpcServer = environment.resolve(GrpcServer.class);
grpcServer.intercept(new ObservableServerInterceptor());

Edit:
I forgot to add the bit where I am trying to get values from the Metadata and when I comment it out, everything works. Here's the code in my intereceptor for the same

final Map<String, String> contextFromRequest = new HashMap<>();
    metadata.keys().stream()
        .forEach(
            key -> {
              Metadata.Key<String> metadataKey =
                  Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER);
              contextFromRequest.put(key, metadata.get(metadataKey));
            });

So may be it's the way I am extracting the values?

0 Answers
Related