2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.