【发布时间】:2017-05-20 15:13:51
【问题描述】:
我正在从第三方提供的 WSDL 创建 Apache CXF 客户端。当我在测试中使用 Web 服务时,我发现服务的输出不符合 WSDL。
到目前为止,对于某些元素,WSDL 似乎没有将它们定义为 nillable=true,而服务实际上确实使用 xsi:nil="true" 返回它们
我的 CXF 客户端无法解组返回的 xml 并崩溃。
我已经在一定程度上解决了它(通过编辑提供的 wsdl ),但我不认为这是一个可行的解决方案。第三方也拒绝将他们的服务和 wsdl 定义统一起来,称其他客户端在生产中正确处理了这一点。
那么,有没有办法让响应的解组变得不那么严格?我可以通过哪些其他途径来解决这个问题?
给我一个问题的字段之一的架构定义如下:
<xsd:element name="cardExpireDate" type="xsd:date"></xsd:element>
该字段由服务返回(在 SoapUI 中调用时)为
<cardExpireDate xsi:nil="true"/>
当我的代码尝试调用 Web 服务时,我收到以下错误(这在堆栈跟踪的下方,但我相信这是问题的根源)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 1515; ]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:417)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:855)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:102)
snip ....
Caused by: javax.xml.bind.UnmarshalException:
- with linked exception:
[java.lang.IllegalArgumentException: ]
... 92 more
Caused by: java.lang.IllegalArgumentException:
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parseYear(Unknown Source)
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(Unknown Source)
我要解析的文档的第 1515 列是
<cardExpireDate xsi:nil="true"/>
【问题讨论】:
-
您是否通过将 schema-validation-enabled 设置为 true 来打开 Schema 验证?然后只需将其关闭即可。这更像是一个 JAXB 而不是 CXF 问题。你能发布具体的例子和错误信息吗?
-
@DennisKieselhorst :我认为我没有打开模式验证 - 我只是使用默认值,我想我读到它默认是关闭的。我会用一些更具体的细节更新这个问题。