My service on Gosu language (Java 11).
I write interceptor for GRPC Server. For it, I must implements next interface from GRPC library :
package io.grpc;
public interface ServerInterceptor {
<ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next);
}
My interceptor should check the JWT token from the metadata and either pass the request on or return an error.
The problem is right at the last step :
class AuthServerInterceptor implements ServerInterceptor {
private static final var AUTHORIZATION_METADATA_KEY = Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)
override function interceptCall<ReqT, RespT>(
call : ServerCall<ReqT, RespT>, headers : Metadata, next : ServerCallHandler<ReqT, RespT>
) : ServerCall.Listener<ReqT> {
try {
var token = headers.get(AUTHORIZATION_METADATA_KEY)
// token checking
return next.startCall(call, headers);
} catch (e : Exception) {
call.close(Status.UNAUTHENTICATED.withDescription(e.Message), headers);
return new ServerCall.Listener<ReqT>() {}
}
}
}
The last line is highlighted in red with an error - The method 'interceptCall<ReqT, RespT>' must be declared with the 'reified' modifier to access the type variable 'ReqT' at runtime.
Mark the overridden function interceptCall() as reified impossible because it's not like that in the interface io.grpc.ServerInterceptor.
I tried different types of wrappers - I still haven't found a solution.
return new ServerCall.Listener<ReqT>() {}. Why do you want to return a new ServerCall listener in case of error anyway? (you may be able to usenew call.Listener(), though)new call.Listener()impossible, I checked now