繁体   English   中英

从不正确的WSDL生成的Apache CXF客户端

[英]Apache CXF Client generated from inaccurate WSDL

我正在从第三方提供的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"/>

如果只有日期字段是问题,则可以使用自定义绑定从cxf-xjc-runtime使用org.apache.cxf.xjc.runtime.DataTypeAdapter:

<jaxws:bindings wsdlLocation="YOUR_WSDL_LOCATION"
          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='THE_NAMESPACE_OF_YOUR_SCHEMA']">
      <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jxb:javaType name="java.util.Date" xmlType="xs:dateTime"
                      parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDateTime"
                      printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDateTime"/>
      </jxb:globalBindings>
  </jaxws:bindings>
</jaxws:bindings>

如果您不知道如何应用绑定,请查看http://cxf.apache.org/docs/wsdl-to-java.html底部的FAQ部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM