How to check spring RestController for unknown query params?
java, rest, spring, spring-mvc, web-services
Solution
Add `HttpServletRequest request` in method parameters, do
String query = request.getQueryString()
in the method body and validate that.
Problem
I have a basic rest controller taking parameters. How can I refuse the connection if the query string contains parameters that I did not define? ``` @RestController @RequestMapping("/") public class MyRest { @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public String content(@PathVariable id, @RequestParam(value = "page", required = false) int page) { return id; } } ``` `localhost:8080/myapp/123?pagggge=1` Currently when calling this url, the method is executed with just the id, and the unknown `paggge` parameter is just neglected. Which is fine in general, but how can I validate them and in case return a HTTP status code?