users@jersey.java.net

Re: [Jersey] Check syntax of query/form parameters?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 28 Jan 2010 10:17:45 +0100

On Jan 28, 2010, at 12:06 AM, Marc Hadley wrote:

> On Jan 27, 2010, at 1:24 PM, Dário Abdulrehman wrote:
>>
>> If I invoke a WS with a typo in one of the query/form parameters it
>> is ignored.
>> Is there a way of forcing an error to be issued when one of the
>> parameters is unknown?
>> My present solution is to inspect the paramters in @Context UriInfo
>> with getQueryParameters but I would like to reject the request if
>> one of the parameters is wrong, without having to write any code,
>> if possible.
>>
> Query params aren't used when mapping a request to a Java method so
> you won't get any automatic error generation if a user sends an
> unknown param or fails to send a required param. Sorry but you'll
> have to write some code !
>

If you want to rely on Jersey specific functionality you can write a
ResourceFilterFactory [1] that can process the request before it is
processed by the resource method.

For example such a filter could look at the annotated parameters of
the resource method and assume that any explicitly declared query
parameters are required, and anything else sent is an error. However,
usually the best thing to do is ignore stuff that you do not know
about, and signal an error for something required that is missing.

Paul.

[1] https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/package-summary.html