Is there any way to configure Spring-MVC to strictly accept a known list of query strings? I'm looking to validate submitted query strings -- if a request has additional query string parameters, I'd like to know about it and return a 404.
My motivations are as follows:
- Clarity: I don't want clients to fat-finger a request parameter, and still get results back (as if no request parameter was supplied)
- HTTP caching: I'd like to limit the number of valid HTTP routes for my service so that HTTP caching (i.e., varnish) will work better
For example, I might have a simple controller that's configured to take one RequestParam
:
@RequestMapping(value = "/selective_route", method = RequestMethod.GET)
public String printTest(@RequestParam String test) {
return test;
}
I now want my app to accept requests and return an OK response for:
/selective_route?test=foo
But I'd want my app to notice that there are additional unaccounted request parameters, and return an ERROR response code.
/selective_route?test=foo&someotherparam=somethingelse