I'm trying to create a filter("pre", 50) that would add default query parameters to the request if these do not exist.
I have based the work so far in a combination of:
To create the new request: http://www.ocpsoft.org/opensource/how-to-safely-add-modify-servlet-request-parameter-values/
To set the new request in the RequestContext object: How to pass modified/wrapped HTTPServletRequest to subsequent Zuul Filters?
Map<String, String[]> extraParams = new TreeMap<String, String[]>();
if (!params.containsKey("language")) {
extraParams.put("language", new String[]{"en"});
params.put("language", Arrays.asList("en"));
}
if (!params.containsKey("country")) {
extraParams.put("country", new String[]{"us"});
params.put("country", Arrays.asList("us"));
}
HttpServletRequest request = ctx.getRequest();
HttpServletRequest wrapped = new WrappedRequest(request, extraParams);
ctx.setRequest(wrapped);
ctx.setRequestQueryParams(params);
I have also modified the RequestQueryParams with the new params but it doesn't seem to work either.
Any ideas?
You will have to create a custom routing filter that adds to the request.
Take a look at the code for RibbonRoutingFilter, it creates a new request based on the incoming request, and then the new request is routed to the service. It plays with the query Params too that might help you to guide you on how to add more params to it.