users@jersey.java.net

[Jersey] Validating call parameters at filter level

From: Derry O Sullivan <derry_at_heystaks.com>
Date: Thu, 13 Sep 2012 08:46:02 +0100

Hi,

I'm looking for an easy way to verify the correct body/query/form/etc
parameters are passed into a request. (and also to warn of
unknown/unneeded parameters) I know i can inject the context of the
request in the actual resource classes and check all the parameters that
way but is there anyway of doing this at the filters?

I've looked into the UriInfo and ExtendedUriInfo which will allow me to
get the resource class/method but don't show parameters.

Resource class:

| @GET
     @Path("/{img_id}")
     @Produces("application/json")
     public Response getImgWithId(
         @PathParam("img_id") @DefaultValue("0") long imgId,
         @QueryParam("user_id") @DefaultValue("-1") long userId)
|

I want to make sure the user passes an img_id path param and the only
other param they can pass is user_id. Any other param should receive a
warning.

I can do it in this method here by checking the vals/injecting the
context but is there a way to do it in an implementation of a
containerRequestFilter on entry to the application?

Thanks!