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

4

2 回答 2

1

JAXB 模型(生成的或手工编码的)在其注释中不包含来自 XML 模式的所有元数据。如果您想针对架构的所有方面进行验证,您可以通过SchemaUnmarshaller.

于 2013-10-03T20:33:03.270 回答
0

我终于找到了这个基于 CXF 的案例的正确答案。

CXF 已经内置了运行时模式验证。它通过配置命名为模式验证,我的代码中唯一缺少的是启用它的 XML,在AKA中已经存在的<jaxws:endpoint元素内:beans.xmlapplication-context.xml

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

由于@Patrick的回答,这一发现成为可能。

于 2013-10-07T14:34:42.997 回答