One of important updates for TomEE done recently (last releases) was to allow the user to configure CXF endpoints (ang get access to advanced configuration/features of CXF). One of them is the schema (xsd) validation of INPUT/OUTPUT messages.
This post will only deal with it but the way to activate it is the same for all properties of the JAXWS CXF endpoint.
First we suppose you have a web service ejb. For instance:
@Stateless @WebService // WS interface is the obvious one you expect public class MyWS implements WS { @Override public String o() { return "ok"; } }
From this point we’ll suppose the EJB name of your webservice is “MyWS”. Then you need to say to OpenEJB/TomEE you want to configure this endpoint. For that simply add an openejb-jar.xml (in WEB-INF for wars) with the following content:
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1"> <ejb-deployment ejb-name="MyWS"> <properties> cxf.jaxws.properties = MyWSProperties </properties> </ejb-deployment> </openejb-jar>
At this moment we just declared that the properties for CXF JAXWS endpoint for the webservice MyWS will be filled in MyWSProperties “Service” (a data container in resources.xml).
To activate schema validation with CXF you just need to set schema-validation-enabled=true in the endpoint properties. So resources.xml looks like:
<resources> <Service id="MyWSProperties" class-name="java.util.Properties"> schema-validation-enabled = true </Service> </resources>
And that’s all :). Now your server will validate inputs/outputs.
It’s realy turn on schema validation! But it use wsdl/schemas generated cxf by self.
How to specify “hand made” wsdl/xsd ?
Hi
I think using https://issues.apache.org/jira/browse/TOMEE-1064 would be enough (should be available tomorrow in the snapshot)
Can we do the similar validatiosn for REST services as well?
Hi Romain
I am trying to do some validations for my REST service and used
@NotNull
@Pattern(regexp=”^[a-zA-Z]\\d[a-zA-Z]$”) annotations in my DTO.
And used @valid annotation in my Rest service for the DTO. But its not doing the validation. I have added
org.apache.openejb.default.system.interceptors = org.apache.openejb.bval.BeanValidationAppendixInterceptor in openejb-jar xml as mentioned in one of your posts. We are using TomEE and JavaEE7 spec.
Thanks
Raj
BeanValidationAppendixInterceptor was removed in tomee 7 since the spec addedit automatically, give a try to @ValidateOnExecution on the method to force it but should be on by default (see https://github.com/apache/tomee/blob/master/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/AutoBValSimpleTest.java)
Hi Romain
I can see validations are failing because of below error. “org.apache.cxf.jaxrs.validation.ValidationUtils.getResourceInstance Service object is not a singleton, use a custom invoker to validate”. When I changed my rest service to Singleton validation is working. Is that the correct solution?
Thanks
Raj
In TomEE it is unlikely since we integrated JAXRSBeanValidation[In|Out]Interceptor to support that but if you configured it yourself it is possible it happens. But this is linked to bean validation, not schema validation