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 14:02:22 +0100

On Jan 28, 2010, at 1:53 PM, Dário Abdulrehman wrote:

> 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, if i may read between the lines, what you are indicating is the
query parameter is a required parameter and if the client does not
send it (because of a typo or otherwise) then it is in error?

Unfortunately JAX-RS does not have a concept of a @Required
@QueryParam notion, but the a filter could support that. And, in the
error response it could state what is required and could look at all
the parameters and do some distance checking between required and
actual parameters to indicate what might be a typo.

Paul.


> 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
>
>