问题
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