users@jersey.java.net

[Jersey] Handling of parameters exceeding datatype in endpoint?

From: <viggo.navarsete_at_gmail.com>
Date: Fri, 18 Feb 2011 20:21:23 +0000 (GMT)

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?