问题描述
我正在尝试修改匹配后过滤器中的查询参数。我无法在预匹配过滤器中执行此操作,因为过滤器逻辑取决于资源类和方法注释。我正在使用 Jersey 2.x 和 Spring Boot。
我无法通过调用 setRequestUri
来修改查询参数,因为它只允许在预匹配过滤器 (https://github.com/firebase/firebase-js-sdk/issues/97#issuecomment-485410026) 中使用。
我不想设置属性,因为这需要更改所有现有服务以从属性中读取。如果没有其他选项可用,我可能需要采用属性方法。
通过调用 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."
}
}
我尝试在线搜索并找到设置请求属性的解决方案。
我发现了另一个 reference,它建议创建一个包装器 (HttpServletRequestWrapper
)。但是在上面的过滤器中,我无权访问 filterChain
。由于过滤器需要访问资源类和资源方法注解,我相信我需要使用Jersey过滤器,不能使用Servlet过滤器(solution)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)