Hi all,

I have to ask the same old schema validation question -- many search hits
but nothing seems to be able to help me.

I found in one of our legacy projects that uses CXF 2.7.8, JAXB-API-2.2.5,
schema validation does not work.

This project uses contract first approach, so schemas are defined first.

Schemas will be converted into java POJOs (with annotations such as
@XMLRootElement etc ) using XJC.

All webservices are annotated with @SchemaValidation.

WSDLs are generated by CXF, they look normal.

Spring is used to link the schema with corresponding webservices.

For example:

    <jaxws:endpoint id="userWS" implementor="#userWSImpl"
implementorClass="com.test.UserWSImpl"
        address="/v1/UserWS"
publishedEndpointUrl="${web.publishedenpoint}/l/v1/UserWS" publish="true">
        <jaxws:schemaLocations>
            <jaxws:schemaLocation>schema/User.xsd</jaxws:schemaLocation>
        </jaxws:schemaLocations>
    </jaxws:endpoint>


What happens now: some of the schema-defined rules such as 'required' will
be captured via the annotations in the java object (by XJC).   They are the
basic rules such as "Required", or "Enumeration".

I can see those ones are shown in the generated WSDL and works well.

However, more complicated rules defined in the schema such as:

   <xs:simpleType name="applicationId">
       <xs:restriction base="xs:string">
           <xs:pattern value="(.{1,10})?"/>
       </xs:restriction>
   </xs:simpleType>

<xs:simpleType name="userid">
   <xs:restriction base="xs:string">
      <xs:pattern value="(\d{10})?" />
   </xs:restriction>
</xs:simpleType>


Are not validated at all.

My expectation is when CXF unmarshall the XML, it would set the schema
referenced to the unmarshaller and validate again the object
automatically.

I searched for the source code and found
org.apache.cxf.jaxrs.provider.AbstractJAXBProvider has the code that
would do the schema validation(in the createUnmarshaller method).

But when I debug it this code is not invoked.

So my question is why the schema validation does not happen? What have
I missed?


Thanks,

Jason

Reply via email to