RestClient and request filter: the http request does not want pass through the filter

694 views
Skip to first unread message

Gianfelice Catini

unread,
Mar 15, 2021, 3:30:38 PM3/15/21
to Quarkus Development mailing list
Hi,
I'm trying to develop a very simple filter/interceptor that should add a header to the http requests made by a @RestClient.
My Quarkus app ignores the filter like it doesnt exist: the http requests complete successfully, but they dont go through the filter.

I reproduced the described behaviour here:
It's a very basic code with a @RestClient and a request filter.

Can anyone help me figure out what i am doing wrong?

Thank you.

Ken Finnigan

unread,
Mar 15, 2021, 3:37:31 PM3/15/21
to diabl...@gmail.com, Quarkus Development mailing list
@Provider annotated filters are only applied to JAX-RS Server requests, not Client ones.

To have a filter added for REST Client you need to add @RegisterProvider(LoggingFilter.class) onto your RestClient interface

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/148ff77e-1fc6-4267-836a-87ac3a65f4bdn%40googlegroups.com.

Gianfelice Catini

unread,
Mar 15, 2021, 3:48:05 PM3/15/21
to Ken Finnigan, Quarkus Development mailing list
Ken, thank you for your quick answer.
I tried to put @RegisterProvider(LoggingFilter.class) in my Rest Client interface (I also removed the @Provider annotation on the LoggingFilter.class), but it didnt solve my problem.
I pushed the new code into the repository.

Ken Finnigan

unread,
Mar 15, 2021, 3:49:58 PM3/15/21
to Gianfelice Catini, Quarkus Development mailing list
Oops, didn't notice it before, but the filter implements the wrong interface. It needs to implement ClientRequestFilter or ClientResponseFilter. ContainerRequestFilter only works on server requests

Gianfelice Catini

unread,
Mar 15, 2021, 5:51:53 PM3/15/21
to Ken Finnigan, Quarkus Development mailing list
I tried to implement the right interfaces (I implemented the ClientRequestFilter and the ClientRequestResponse both), but the client requests/responses dont go through the filter.
I pushed the code again.

Thank you for your patience and your answers.

Gianfelice Catini

unread,
Mar 15, 2021, 7:18:12 PM3/15/21
to Quarkus Development mailing list
I found the mistake: it was an error on my test method (bad usage of the rest client).
Ken, thank you for your support: I followed your hints and now it works well.

Ken Finnigan

unread,
Mar 15, 2021, 7:32:44 PM3/15/21
to Gianfelice Catini, Quarkus Development mailing list
Reply all
Reply to author
Forward
0 new messages