cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: CXF-5309 Support Bean Validation API for JAX-RS
Date Thu, 16 Jan 2014 15:55:38 GMT
Hi
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:
> https://issues.apache.org/jira/browse/CXF-5309
>
> This issue is  fixed in the release 3.0.0-milestone1<https://issues.apache.org/jira/browse/CXF/fixforversion/12323927>
>
> Unfortunately my company use cxf release 2.7.8 and do not plane for the moment to use
3.0
>
> 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 = 
factory.getValidator().forExecutables();

         final Set< ConstraintViolation< T > > violations = 
methodValidator.validateParameters(instance,
             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.
>
>


Mime
View raw message