users@jersey.java.net

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

From: Dário Abdulrehman <dario.rehman_at_gmail.com>
Date: Thu, 28 Jan 2010 12:53:26 +0000

In my case if the user makes a typo in a query param and I ignore it, the WS
might return unexpected results which can take a while for the user to
figure the cause.
So I opted to access all the query params using UriInfo and explicitly check
for unknown parameters.

Thanks.

On Thu, Jan 28, 2010 at 9:17 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

>
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>