[grpc-java] how to get request class info in ServerInterceptor

16 views
Skip to first unread message

최상용

unread,
Jul 4, 2022, 1:17:41 PMJul 4
to grpc.io
I hope get request class Info in ServerInterceptor
Is it possible ?
If it is possible, tell me way

example code

class ExampleInterceptor implements ServerInterceptor {
        @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
            ServerCall<ReqT, RespT> call,
            Metadata headers,
            ServerCallHandler<ReqT, RespT> next
    ) {
        Class<ReqT>  class =  ?

        return next.startCall(call, headers);
    }
}

최상용

unread,
Jul 4, 2022, 1:36:16 PMJul 4
to grpc.io
I seem to find solution.
I share for people who same trouble as me

class ExampleInterceptor implements ServerInterceptor {
        @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
            ServerCall<ReqT, RespT> call,
            Metadata headers,
            ServerCallHandler<ReqT, RespT> next
    ) {
        MethodDescriptor.ReflectableMarshaller  reflectableMarshaller = (MethodDescriptor.ReflectableMarshaller) request.getMethodDescriptor().getRequestMarshaller()
        Class<ReqT> requestClassInfo = reflectableMarshaller.getMessageClass()
        return next.startCall(call, headers);
    }
}
2022년 7월 5일 화요일 오전 2시 17분 41초 UTC+9에 최상용님이 작성:
Reply all
Reply to author
Forward
0 new messages