问题
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?
回答1:
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());
}
}
}
来源:https://stackoverflow.com/questions/56448061/how-can-i-add-an-http-interceptor-to-a-quarkus-application