users@jax-rs-spec.java.net

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

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Wed, 6 Nov 2013 15:25:17 +0000

On 06/11/13 14:24, Santiago Pericas-Geertsen wrote:
>
> On Nov 6, 2013, at 7:15 AM, Sergey Beryozkin <sberyozkin_at_talend.com> 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?

Yes. However if we have BeanVal done by CDI then may be it is not much
of an issue because the exception will be reported much earlier, it is
only when we have no CDI/etc managing it when the issue of what to do
with the singleton-related exceptions arises. May be it is worth keeping
it unspecified for now.

Thanks, Sergey

>
> -- Santiago
>
>


-- 
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com