Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use GlobalInterceptor gRPC annotation with interceptor produced by a method #21358

Closed
vladykin opened this issue Nov 11, 2021 · 6 comments · Fixed by #34348
Closed

Can't use GlobalInterceptor gRPC annotation with interceptor produced by a method #21358

vladykin opened this issue Nov 11, 2021 · 6 comments · Fixed by #34348
Labels
area/grpc gRPC kind/enhancement New feature or request
Milestone

Comments

@vladykin
Copy link

Describe the bug

I have a server interceptor produced by a method:

  @Produces
  public ServerInterceptor serverInterceptor() {
    return new LoggingServerInterceptor();
  }

I want to make it global by putting io.quarkus.grpc.GlobalInterceptor annotation.

I can't put this annotation on the producer method, because the annotation has @Target({ FIELD, PARAMETER, TYPE }) (not applicable to methods).

And I can't put this annotation on LoggingServerInterceptor class, because the class does not have any CDI bean annotations on it. Quarkus complains:

2021-11-11 04:23:49,640 ERROR [io.qua.grp.run.GrpcServerRecorder] (main) Unable to start the gRPC server: java.lang.IllegalArgumentException: Server interceptor class class com.azul.cc.infrastructure.grpc.LoggingServerInterceptor is not a CDI bean. Only CDI beans can be used as gRPC server interceptors. Add one of the scope-defining annotations (@Singleton, @ApplicationScoped, @RequestScoped) on the interceptor class.

Expected behavior

The GlobalInterceptor annotation should support this case as well.

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.4.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@vladykin vladykin added the kind/bug Something isn't working label Nov 11, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 11, 2021

/cc @cescoffier, @michalszynkiewicz

@michalszynkiewicz
Copy link
Member

michalszynkiewicz commented Nov 15, 2021

@vladykin Thank you for your report!

A workaround, if you cannot add a scope-defining annotation on the interceptor class, would be to subclass it and add the annotations on the subclass:

@ApplicationScoped
@GlobalInterceptor
public class MyLoggingServerInterceptor extends LoggingServerInterceptor {
}

@michalszynkiewicz
Copy link
Member

I took a deeper look into it and it's not trivial to implement.
Moreover, I believe the workaround above should let users handle all their use cases.
Please let me know if it doesn't work for you.

@michalszynkiewicz michalszynkiewicz added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Nov 16, 2021
@michalszynkiewicz michalszynkiewicz removed their assignment Nov 16, 2021
@vladykin
Copy link
Author

Thank you, I can use the suggested workaround or put the CDI annotation directly on the LoggingServerInterceptor.
My personal preference is to use producer methods for constructing and configuring beans, but if that's not possible in this case, I can live with that.

@michalszynkiewicz
Copy link
Member

I understand it's more convenient in some cases, I'm not closing this issue.
What I wanted to say is that, having a work around, and being non-trivial, I don't consider this a high priority feature request.

@slinkydeveloper
Copy link

slinkydeveloper commented Sep 19, 2022

I stumbled on this issue and I was wondering, would it be possible to use the Produces annotation at least for service scoped interceptors? It would be nice to reuse existing interceptors without wrapping them in new classes.

nahguam added a commit to nahguam/quarkus that referenced this issue Jun 27, 2023
nahguam added a commit to nahguam/quarkus that referenced this issue Jun 27, 2023
@quarkus-bot quarkus-bot bot added this to the 3.3 - main milestone Jun 28, 2023
michelle-purcell pushed a commit to michelle-purcell/quarkus that referenced this issue Jun 28, 2023
michelle-purcell pushed a commit to michelle-purcell/quarkus that referenced this issue Jun 28, 2023
phillip-kruger pushed a commit to phillip-kruger/quarkus that referenced this issue Jul 6, 2023
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Jul 31, 2023
@aloubyansky aloubyansky modified the milestones: 3.3.0.CR1, 3.2.8.Final Oct 31, 2023
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grpc gRPC kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants