I'm building a Java grpc server and I'm having a hard time getting the request headers. The proto files are compiled using protobuf-maven-plugin, and based on the generated stubs, I can't access the context or the request metadata.
I've also tried to define a list of key/values in the message request, hoping the grpc will take care of the headers mappings, but no luck so far.
Any idea how I can get access the headers?
Thanks!
My proto files content:
...
// Version Request
message VersionRequest {
// key/value pairs
repeated Header headers = 1;
}
message Header {
//key
string key = 1;
//value
string constant = 2;
}
...
...
security_definitions: {
security: {
key: "clientIdAuth";
value: {
type: TYPE_API_KEY;
in: IN_HEADER;
name: "x-client-id";
}
}
security: {
key: "clientSecretAuth";
value: {
type: TYPE_API_KEY;
in: IN_HEADER;
name: "x-client-secret";
}
}
security: {
key: "bearerAuth";
value: {
type: TYPE_API_KEY;
in: IN_HEADER;
name: "Authorization";
}
}
}
...
// Retrieves system version
//
// Retrieves system version
rpc GetVersion(VersionRequest) returns (Version) {
option (google.api.http) = {
get : "/api/v4/version"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
security: {
security_requirement: {
key: "clientIdAuth";
value: {}
}
security_requirement: {
key: "clientSecretAuth";
value: {}
}
security_requirement: {
key: "bearerAuth";
value: {}
}
}
};
}
...
The server side implementation looks like this:
...
@GrpcService
public class GrpcAPIService extends MixAPIGrpc.MixAPIImplBase {
@Autowired
private MwProxy mwProxy;
@Override
public void getVersion(VersionRequest versionRequest, StreamObserver<Version> streamObserver) {
System.out.println("===============" + versionRequest.getHeadersCount());
handleEGrpcCall("getVersion", mwProxy::getVersion, streamObserver);
}
...
versionRequest.getHeadersCount() always returns 0, although there are 3 headers sent in all my requests.