1

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"?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow. +1 already. I am going to read your article thoroughly and let you know if that worked for me. Do I understand correctly that this implies also setting my own ValidationEventHandler?
OK, I tried to implement your solution but I have no main() in my CXF-generated code. Where do I hook the Schema and Unmarshaller code?
Looks like I am approaching this the wrong way (because CXF is involved): According to this, the presence of the cxf.xml configuration file on the classpath (and its content) change CXF's default behavior that message parameters would not be validated. This is confusing because I can definitely get an "unmarshaling error" (by default!) if I send a "?" instead of an xs:timestamp... What am I missing?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.