users@jersey.java.net

[Jersey] Re: Handling of parameters exceeding datatype in endpoint?

From: Mark Petrovic <mspetrovic_at_gmail.com>
Date: Sun, 20 Feb 2011 07:30:17 -0800

You may also be able to use an injectable provider like this to pre-digest
the input before your resource method starts its work:

http://codahale.com/what-makes-jersey-interesting-injection-providers/

Basically, you can inject a custom type as long as you tell Jersey how to
synthesize it from the input.

On Sat, Feb 19, 2011 at 5:51 AM, Martin Matula <martin.matula_at_oracle.com>wrote:

> Hi,
> You can use Long instead of Integer which will give you a wider range, but
> I guess is still not what you want.
> Other option is to write your own StringReader (StringReaders are used by
> Jersey to convert QueryParams to a particular type).
> Regards,
> Martin
>
> On Feb 18, 2011, at 9:21 PM, viggo.navarsete_at_gmail.com wrote:
>
> > I have REST endpoint defined like this:
> > {code}
> > @GET
> > @Path("MyEndpoint")
> > public Response executeMyEndpoint(
> > ...
> > @javax.ws.rs.QueryParam("pageSize") Integer pageSize,
> > @javax.ws.rs.QueryParam("pageNumber") Integer
> > pageNumber,
> > ...) {
> > if( pageNumber != null && ( pageNumber < 1 ||
> > pageNumber > Integer.MAX_VALUE / pageSize ) ) {
> > return Response.status( Status.BAD_REQUEST
> > ).type( MediaType.TEXT_PLAIN )
> > .entity( "Page number must be
> > in the interval [1, " + Integer.MAX_VALUE + " / pageSize] (including
> > endpoints) or omitted." )
> > .build();
> > }
> > ...my code...
> > }
> > {code}
> >
> > It means that I put some additional restriction on the values of
> > {{pageNumber}} (except the restriction to {{Integer}} type). If user
> > passes value which is not within these boundaries, the REST endpoint
> > returns the error message I specified. However, if it's not even within
> > Integer datatype range, the endpoint returns always HTTP 404 error
> > saying "description The requested resource () is not available", which
> > is not too user friendly. Is there better option how to handle these
> > corner cases than define pageNumber and pageSize as String and do the
> > parsing myself?
>
>


-- 
Mark