[jax-rs-spec users] [jsr339-experts] Re: Resource Class Validation

From: Santiago Pericas-Geertsen <>
Date: Wed, 6 Nov 2013 09:24:26 -0500

On Nov 6, 2013, at 7:15 AM, Sergey Beryozkin <> wrote:

> Hi Santiago, All
> I'd like to ask few more questions about Chapter 7.
> First, how to validate resource classes themselves.
> 7.6 says:
> "Constraint annotations are allowed in the same locations as the following annotations: @MatrixParam, ..., *except in class construc-
> tors and property setters*.
> ...
> The same caveats related to the use of other JAX-RS annotations in resource classes apply to
> constraint annotations. For example, *a constraint validation annotating a constructor parameter* in a resource
> class whose lifecycle is singleton will only be executed once.
> "
> I'm assuming that what it says that we do not validate the resource class during the initialization (via the constructor or when injecting the properties via setters) and we move to Phase 2:

 Yes, the class is validated in phase 2. However, this is all explained for the default per-request lifecycle. Other lifecycles are beyond the scope of the spec.

> "Phase 2 Validate annotations on resource classes, fields and property getters (if enabled)."
> The question here is what happens when a singleton root resource fails the validation ? I recall we had a callback handler in API but it has gone, so am I right to assume that the runtime would need to synchronize during the request processing and ensure that a singleton resource is validated only once ?

 In the singleton case, again not in the spec, I'd assume you'd want to do Phases 1 and 2 when the instance is created and Phases 3 and 4 on every request? How does your implementation deal with singleton injections? We have an exception mapper for ValidationException, but it isn't of much use for a singleton instantiated before the first request comes, is that your point?

-- Santiago