如何将修改/包装的HTTPServletRequest传递给后续的Zuul过滤器? [英] How to pass modified/wrapped HTTPServletRequest to subsequent Zuul Filters?
问题描述
现在,我想将这个自定义包装的请求传递给下一个Zuul预过滤器(Filter2)。我怎样才能做到这一点?
在使用常规的Servlet过滤器之前,我们在Filter1中使用以下代码:
chain.doFilter(new CustomRequestWrapper(request,extra),response);但是,在Zuul过滤器中,Zuul框架负责调用后续的过滤器,并将请求/请求传递给/响应对象。如何重写?解决方案在Filter1执行结束之前,请调用以下内容来覆盖现有的HTTPServletRequest定制请求
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
。
。
。
context.setRequest(new CustomRequestWrapper(request,extra));
We have a Zuul Pre-Filter (Filter1) which will inspect the incoming HTTPServletRequest and make some changes to the query parameters in it to embed it to a custom created request (wrapping HttpServletRequestWrapper).
Now, i want to pass this custom wrapped request to the next Zuul Pre-Filter (Filter2). How can i do that ?
Earlier when using regular Servlet Filters, we use as following in my Filter1
chain.doFilter(new CustomRequestWrapper(request, extra), response);
but, in Zuul Filter, the Zuul framework takes care of invoking the subsequent filters and passing the request/response objects. How can i override that ?
解决方案 Before the Filter1 execution ends, call the following to over-write the existing HTTPServletRequest with our wrapped custom request
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
.
.
.
context.setRequest(new CustomRequestWrapper(request, extra));
这篇关于如何将修改/包装的HTTPServletRequest传递给后续的Zuul过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!