java - 如何在 Jersey 2 的 postfilter 中修改查询参数
问题描述
我正在尝试修改后匹配过滤器中的查询参数。我不能在预匹配过滤器中执行此操作,因为过滤器逻辑取决于资源类和方法注释。我正在使用 Jersey 2.x 和 Spring Boot。
我无法通过调用来修改查询参数,setRequestUri
因为它仅在预匹配过滤器(参考)中允许。
我不想设置属性,因为这需要更改所有现有服务以从属性中读取。如果没有其他选项可用,我可能需要使用属性方法。
通过调用注册过滤器ResourceConfig#register(cls, priority)
过滤器类实现ContainerRequestFilter
.
public class MyFilter implements ContainerRequestFilter {
@Override
public void filter(final ContainerRequestContext requestContext) {
// modifiedUri is the uri with modified query params
// requestContext.setRequestUri(modifiedUri) ==> Throws IllegalStateException - "Method could be called only in pre-matching request filter."
}
}
我尝试在线搜索并找到设置请求属性的解决方案。我找到了另一种建议创建包装器( )的解决方案HttpServletRequestWrapper
。但是在上面的过滤器中,我无法访问filterChain
. 由于过滤器需要访问资源类和资源方法注解,我相信我需要使用 Jersey 过滤器并且不能使用 Servlet 过滤器(参考)。
解决方案
推荐阅读
- javascript - 为外部模块的路由添加路由前缀?
- .net - DevExpress 在设计模式下打开时要求检查 Winforms
- python - 新文件中的 IDLE 自动完成功能不起作用
- c++ - Call not default object constructor for each object uniquely when creating a vector of objects
- python - 如何限制正则表达式不匹配少数实例
- java - 如何对 Java 8 流进行单元测试?
- r - 提高我在 R 中的循环的性能
- java - 创建 BiConsumer 作为没有反射的字段设置器
- maven - 启动payara 5 遇到过
- javascript - 将我的数组的结构更改为对象