Sergey,

The wadl2java extraarg "-beanValidation" works like a charm, thanks a lot - now everything I need is a JEE 7 container :).

However, there are some things I have to note:

1.) ValidationExceptionMapper:
Regarding how the ConstraintViolationException is returned with org.apache.cxf.jaxrs.validation.ValidationExceptionMapper:

I sent an invalid json request to the server.

a) It does respond with 500, but should be 400.

b) The response payload is XML, not json (method has @Produces({"application/json" }))

Response-Code: 500
Encoding: UTF-8
Content-Type: application/json
Headers: {}
Payload: <ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat";><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat";>javax.validation.ConstraintViolationException</ns1:faultstring></ns1:XMLFault>

c) It would be nice to have addMessageToResponse flag as WebApplicationExceptionMapper to get the error details.


2.) Request parameter beanvalidation:
I tried to add @NotNull annotation to a request parameter in the implementation class (thus trying to work around the missing support of beanvalidation of wadl2java). If I add @NotNull to a request parameter in the implementation class, and fill it in the request, I still get an error 500 with exception in log:

javax.validation.ValidationException: Service Object is null
at org.apache.cxf.validation.BeanValidationInInterceptor.checkNotNull(BeanValidationInInterceptor.java:49) ~[cxf-core-3.1.6.jar:3.1.6]

It seems as if request parameters are not filled with their values of the request before the validation is done in BeanValidationInInterceptor.
If I remove the @NotNull-annotation, everything works.

What do you think?

Best regards,
Johannes


Am 29.08.2016 um 22:31 schrieb Sergey Beryozkin:
I've added a 'beanValidation' option:

https://issues.apache.org/jira/browse/CXF-7032

I'll resolve it once I complete the test

Sergey
On 29/08/16 11:00, Sergey Beryozkin wrote:
On 29/08/16 10:46, Vjacheslav V. Borisov wrote:
2016-08-27 18:58 GMT+04:00 J. Fiala <mod...@fwd.at>:

Sergey,

OK, so there is no option to get query parameter validation for
wadl2java
generated java sources in the near future?

So if query parameter validation is desired, one has to switch to
Swagger
as contract and generate the BeanValidation-annotations using
Swagger-Codegen or use code first, right?


We extensively develop microserices, an rarely need compex query
parameters, this is almost Date or UUID ones in query string
All other data transfered in xml/json payload (which validation is
possible)

Thanks, yes, this is similar to what I was planning to reply with.

In the vast majority of cases query/header/cookie parameters are simple
properties. Doing the complex mapping from WADL grammar to individual
Bean validation properties only for the sake of enforcing some digital
or string pattern in such (query) properties and then also making sure
it works the other way around (WADL grammar is auto-enhanced based on
the avail BeanVal annotations during WADL generatiopn) is not worth it
IMHO, especially that it will also overloads WADL grammar.

Cheers, Sergey




Reply via email to