cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: CXF-5309 Support Bean Validation API for JAX-RS
Date Thu, 16 Jan 2014 15:55:38 GMT
On 16/01/14 13:02, PEIFFER, ERIC (ERIC) wrote:
> Hello everybody,
> I'm very interested about this correction concerning the support of bean validation:
> This issue is  fixed in the release 3.0.0-milestone1<>
> Unfortunately my company use cxf release 2.7.8 and do not plane for the moment to use
> It would be great if someone could implements the correction in the 2.7.x  bracnch.
I'm not sure it is realistic, it is really a new feature of CXF 3.0.0.
The easy enough approach is to write a custom interceptor in CXF 2.7.8 
which will do the validation. The 3.0.0 implementation attempts to be 
complete in that all sort of configuration options are covered, various 
possible scenarios, etc but for a given case it can be done the much 
simpler way,

All one needs to do for a simple case is to create a ValidationProvider, 
and ask to validate the input and/or output values, the former task can 
be done like this:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

and then validating input parameters:

final ExecutableValidator methodValidator = 

         final Set< ConstraintViolation< T > > violations = 
             method, arguments);

         if (!violations.isEmpty()) {
             throw new ConstraintViolationException(violations);

and handle the exception accordingly;

The actual instance, method and parameter values can easily be obtained 
from a current CXF message.

Let me know please if you'd like to try it in CXF 2.7.8, I'll then 
provide more info

Cheers, Sergey

> Regards,
> Eric.

View raw message