我有一个Web服务,它在webTypes
部分定义了几个模式。我定义了一个read
操作,该类型在此模式中定义:
<xs:schema version="1.0" targetNamespace="http://example.com/webservice/service" xmlns:ns0="http://example.com/webservice/parameter" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://example.com/webservice/parameter"/>
<xs:complexType name="read">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="filter" type="ns0:filter" minOccurs="0" maxOccurs="1"/>
<xs:element name="startIndex" type="xs:int" minOccurs="1" maxOccurs="1" />
<xs:element name="noOfResults" type="xs:int" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:element name="read" type="tns:read"/>
</xs:schema>
然后我在CXF配置文件中激活架构验证,如下所示:
<jaxws:endpoint id="dataService"
implementor="com.example.webservice.jaxws.endpoint.SIB"
address="/DataService"
wsdlLocation="classpath:DataService.wsdl">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
我测试了我的模式,用SOAPUI验证器验证了我的一些请求,它运行得很好。但在服务器端,当收到请求时,我收到此错误:
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'name'.]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:768)
... 287 more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'name'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:96)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
... 289 more
任何线索?似乎验证器可以访问“读取”操作定义。我不知道该怎么做,因为实际上webservices在没有模式验证的情况下正常工作,但我想避免在Web服务实现中进行param验证。
提前致谢,
注意我正在使用带有JAXWS 2.2的CXF 2.3.3和带有java 1.6.0的非认可tomcat 6中的JAXB 2.2.1。