1

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.

3
  • I don't think you can do that 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 use new call.Listener(), though) Commented Dec 10, 2024 at 19:49
  • @njzk2 Hello. Why - it is from official example - link. Using new call.Listener() impossible, I checked now Commented Dec 12, 2024 at 17:23
  • interesting. could be an earlier version of java? Commented Dec 12, 2024 at 20:36

1 Answer 1

0

Yes you cannot just return new call.Listener() as the return type needs to be a ServerCall.Listener<ReqT> . Unfortunately we are not expert enough with Gosu to suggest how to resolve your compilation error.

Sign up to request clarification or add additional context in comments.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.