How to pass modified/wrapped HTTPServletRequest to subsequent Zuul Filters?

一曲冷凌霜 提交于 2020-01-11 11:52:30

问题


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 ?


回答1:


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));

Reference: http://netflix.github.io/zuul/javadoc/zuul-core/com/netflix/zuul/context/RequestContext.html#setRequest(javax.servlet.http.HttpServletRequest)



来源:https://stackoverflow.com/questions/30400817/how-to-pass-modified-wrapped-httpservletrequest-to-subsequent-zuul-filters

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