users@jersey.java.net

query parameter validation

From: Brian Moseley <bcm_at_maz.org>
Date: Tue, 27 Jul 2010 20:22:38 -0400

I'm looking for ways to validate the values of the
@QueryParam-annotated fields of my resource class using JSR-303
validation. the idea is to use additional annotations to describe the
types of validation required for each field. for example (in scala):

class FooResource {
  @QueryParam @NotNull @Size(min=2, max=20) var foo: String = _
  // ... resource methods etc
}

it seems intuitively appropriate to use a resource filter to step in
before the resource method fires and perform validation on the
resource after query param values have been type-cast and injected,
but I haven't found a way to give the filter access to the resource. I
can't inject the resource into the filter can I?

certainly I could inject the query params as resource method params,
but I have several resource methods across a half dozen classes that
all accept the same set of query params (which are actually defined in
a trait shared by the resource classes), so that's not really a
feasible solution for me.

am I missing something about resource filters? is there another way to
accomplish this goal?

thanks!