Question

I implemented a working web service using CXF (2.7.1) with a WSDL & XSD that include, among other things, the following type:

<xs:simpleType name="SimpleIdType">
  <xs:restriction base="xs:string">
    <xs:pattern value="[A-Za-z0-9:\.\-]{20}"/>
  </xs:restriction>
</xs:simpleType>

I interpret this to be: Accept only 20 character strings which only contain alphanumeric characaters and ':', '.' and '-'.

When I send a SOAP message to my web service with the corresponding element containing FAAAAAAAAAAAAAAAAAAA, the service of course accepts properly without any error.

However, if I send an identical SOAP message with the # instead of F (i.e. #AAAAAAAAAAAAAAAAAAA), the service still accepts the message, without issuing any validation error (unmarshalling or otherwise).

Why?

Isn't the default ValidationEventHandler supposed to handle that by throwing an "Unmarshalling Error"?

Was it helpful?

Solution 2

I finally found the correct answer for this CXF-based case.

CXF already has runtime schema validation built-in. It is named schema validation via configuration and the only thing that was missing in my code was the XML to enable it, inside the already existing <jaxws:endpoint element in beans.xml AKA application-context.xml:

<jaxws:properties>
    <entry key="schema-validation-enabled" value="true" />
</jaxws:properties>

This discovery was made possible thanks to the answer by @Patrick.

OTHER TIPS

The JAXB model (generated or hand coded) does not contain all the metadata from the XML schema in its annotations. If you want to validate against all aspects of the schema you can enable this be specifying an instance of Schema on the Unmarshaller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top