grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

Could not add interceptor(s) to `ProtoReflectionService`

Open jyane opened this issue 9 years ago • 4 comments

What did you do?

Add interceptor(s) to ProtoReflectionService.

What did you expect to see?

ProtoReflectionService works with interceptor(s).

What did you see instead?

Got a NullPointerException or compilation error.

Problem

I ask a question on Gitter. https://gitter.im/grpc/grpc?at=59b9090bcfeed2eb65033bad and I have got a reply from @e.jona86. https://gitter.im/grpc/grpc?at=59b9a7f9c101bc4e3ac3404a I think it is not easy to fix. So I report an issue.

ProtoReflectionService needs a reference to Server via notifyOnBuild but it could not, because an intercepted service is an instance of ServerServiceDefinition.

I think it is consisting some problems (may not a bug or may not a problem) as below.

  • ServerInterceptors#intercept binds a service and returns ServerServiceDefinition.
  • ServerBuilder#addService doesn't add ServerServiceDefinition to notifyOnBuildList.
  • ServerServiceDefinition doesn't implement InternalNotifyOnBuild.

Therefore, I could not add interceptor(s) to ProtoReflectionService.

jyane avatar Sep 15 '17 08:09 jyane

@ericgribkoff, were we aware of this limitation during the design?

ejona86 avatar Sep 15 '17 17:09 ejona86

@ejona86 No, I don't think so. This was an oversight on my part. I'll look into getting the mechanism working with server interceptors.

ericgribkoff avatar Sep 15 '17 17:09 ericgribkoff

As I mentioned in #3449, we could add a field of a method to run to ServerServiceDefinition as a replacement for InternalNotifyOnBuild.

Note: you may be able to use ServerBuilder.intercept() as a workaround. As long as you're okay with the interceptor applying to all services, that would work.

ejona86 avatar Nov 08 '17 15:11 ejona86

Thank you for your reply, it works. But I want to add interceptor(s) to each services. I'm waiting for resolving this issue because it seems to be hard to resolve for me...

jyane avatar Dec 10 '17 17:12 jyane