I would like to add an HTTP interceptor to my Quarkus application so I can intercept all HTTP requests. How can such that be achieved?
Asked
Active
Viewed 1.9k times
1 Answers
25
Quarkus uses RESTEasy as its JAX-RS engine. That means that you can take advantage of all of RESTEasy's features, including Filters and Interceptors.
For example to create a very simple security mechanism, all you would need to do is add code like the following:
@Provider
public class SecurityInterceptor implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext context) {
if ("/secret".equals(context.getUriInfo().getPath())) {
context.abortWith(Response.accepted("forbidden!").build());
}
}
}
It should be noted that this only works for requests that are handled by JAX-RS in Quarkus. If the requests are handled by pure Vert.x or Undertow, the filtering mechanisms of those stacks will need to be used.
UPDATE
When using RESTEasy Reactive with Quarkus, the @ServerRequestFilter
annotation can be used instead of implementing ContainerRequestFilter
.
See this for more information

geoand
- 60,071
- 24
- 172
- 190
-
4I'd just add that (AFAIK) this will only work for the requests routed to JAX-RS, while you can also have Undertow and Vert.x HTTP endpoints. Those have their own filtering mechanisms. – Ladicek Jun 05 '19 at 06:51
-
@Ladicek can you put some more light on your response? – мalay мeнтa Sep 20 '20 at 07:13
-
what is the difference between `ContainerRequestFilter` and `@ServerRequestFilter` ? Which one will be executed first ? – Olivier Boissé Jan 03 '23 at 15:55
-
They are essentially the same thing, with the annotation form being easier to use – geoand Jan 04 '23 at 05:58
-
ContainerRequestFilter dosen't work with Camel REST endpoint, any guess why? – kingkong Jul 24 '23 at 10:09