Search code examples
filterservlet-filtersnetflixnetflix-zuul

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


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 ?


Solution

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