users@jersey.java.net

Re: [Jersey] query parameter validation

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 28 Jul 2010 12:50:42 +0200

Hi Brian,

One or more configured resource filters will be called just before a
resource method is invoked.

If you inject UriInfo into your resource filter factory (and pass the
reference along to the request filter) then you can obtain the the
matched resource using:

https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/UriInfo.html
#getMatchedResources%28%29

Paul.

On Jul 28, 2010, at 2:22 AM, Brian Moseley wrote:

> 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!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>