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

ClientRequestFilter executed on every Client instead of only the one where it is registered. #41859

Closed
Chrisx0385 opened this issue Jul 12, 2024 · 5 comments
Labels
area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@Chrisx0385
Copy link

Chrisx0385 commented Jul 12, 2024

Describe the bug

The ClientRequestFilter executed on every Client instead of only the one where it is registered. We have two clients:

@RegisterRestClient(configKey = "dad")
@RegisterProvider(TheClientRequestFilter.class)
public interface DadJokeClientWithFilter {
@RegisterRestClient(configKey = "random")
public interface RandomJokeClient {

And the Filter:

public class TheClientRequestFilter implements ClientRequestFilter {
    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
        Log.info(requestContext.getUri());
    }
}

Expected behavior

When I use the clients I would expect the filter only to be executed when the DadJokeClient is used since it is only registered there, but it will also be executed for the RandomJokeClient.

Actual behavior

        Log.info("Start");
        Log.info(dadJokeClientWithFilter.get());
        Log.info(randomJokeClient.get());
        Log.info("End");

This leads to the following output:

2024-07-12 11:40:19,652 INFO  [app.JokeService] (Quarkus Main Thread) Start
2024-07-12 11:40:19,653 INFO  [ada.out.TheClientRequestFilter] (Quarkus Main Thread) https://icanhazdadjoke.com/
2024-07-12 11:40:19,886 INFO  [app.JokeService] (Quarkus Main Thread) {"id":"1oGYLu4T7Ed","joke":"Why is Peter Pan always flying? Because he Neverlands.","status":200}

2024-07-12 11:40:19,888 INFO  [ada.out.TheClientRequestFilter] (Quarkus Main Thread) https://official-joke-api.appspot.com/random_joke
2024-07-12 11:40:20,179 INFO  [app.JokeService] (Quarkus Main Thread) {"type":"general","setup":"What do you call a cow with no legs?","punchline":"Ground beef!","id":57}
2024-07-12 11:40:20,179 INFO  [app.JokeService] (Quarkus Main Thread) End

The TheClientRequestFilter logs the urls of both clients.

How to Reproduce?

I've created a repo with this demo code here:
https://github.com/Chrisx0385/rest-client-bug-showcase

Output of uname -a or ver

No response

Output of java -version

21

Quarkus version or git rev

3.12.2

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

No response

Additional information

No response

@geoand
Copy link
Contributor

geoand commented Jul 12, 2024

Thanks for reporting.

Can you please open up your reproducer? I'm getting 404

@Chrisx0385
Copy link
Author

Oh, yep, it is public now :)

@geoand
Copy link
Contributor

geoand commented Jul 15, 2024

This is actually the specified behavior, see #18560.

In your case, if you don't use @Provider on TheClientRequestFilter, then you get the behavior you wanted.

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
@geoand geoand added the triage/invalid This doesn't seem right label Jul 15, 2024
@Chrisx0385
Copy link
Author

Ah, good to now, thank you :)

@geoand
Copy link
Contributor

geoand commented Jul 16, 2024

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants