views:

68

answers:

1

Title pretty much says it all. One of the requirements of a web service I'm working on is that if a query param name is given that is either invalid or not case-exact with what's expected, it should give an error saying so.

Is there anything in Spring MVC that can do this via configuration or some kind of setting? I imagine it's possible to code it, but I think that'd be a lot uglier.

+1  A: 

The way I do this is to write a base class that defines methods for getting mandatory and optional query parameters. These throw exceptions that are intercepted (again) in the base class and turned into 400 responses.

I would not bother with trying to diagnose query parameters whose name is unrecognised / has the wrong case. Query parameter names are typically hard-wired into HTML, Javascript, etc written by developers. They should be able to find out what is valid by reading the web-api documentation. Once they've debugged their code, any special code in the servlet to pick up unexpected parameters is just a runtime overhead.

Stephen C
Yeah, I'm not really sure why the behavior is desired -- I don't think many REST services bother with it. Perhaps I can talk them out of wanting it. Thanks.
AHungerArtist