CXF schema validation with TomEE

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:

@WebService // WS interface is the obvious one you expect
public class MyWS implements WS {
    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="">
  <ejb-deployment ejb-name="MyWS">
    <properties> = MyWSProperties

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:

  <Service id="MyWSProperties" class-name="java.util.Properties">
    schema-validation-enabled = true

And that’s all :). Now your server will validate inputs/outputs.


7 thoughts on “CXF schema validation with TomEE

  1. Romych

    It’s realy turn on schema validation! But it use wsdl/schemas generated cxf by self.
    How to specify “hand made” wsdl/xsd ?

    1. Raj

      Hi Romain
      I am trying to do some validations for my REST service and used
      @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.


      1. Raj

        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?


      2. rmannibucau Post author

        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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s