有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在运行时打开/关闭JAXRS过滤器/拦截器

我有一个日志过滤器(或拦截器),它将HTTP请求和响应详细信息记录到数据库中。由于性能原因,有时我希望在运行时根据示例a*中的值打开和关闭过滤器。属性文件

这是我的JAX-RS过滤器:

@Provider
public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        // logging request details to database
    }

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
        // logging response details to database
    }
}

我可以在过滤器的开头添加if条件,但这不是我想要做的。如果可能的话,我想以某种方式连接/分离过滤器


共 (0) 个答案