How can I add an http interceptor to a Quarkus application?

血红的双手。 提交于 2020-08-08 06:10:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!