我正在使用WSDL生成Java类,以访问Zuora SOAP API。
不幸的是,此WSDL存在冲突:Maven CXF插件引发错误,消息为“两个声明导致ObjectFactory类发生冲突”。
冲突发生在Invoice.PaymentAmount和Payment.Amount
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:zns="http://api.zuora.com/"
xmlns:ons="http://object.api.zuora.com/"
xmlns:fns="http://fault.api.zuora.com/"
targetNamespace="http://api.zuora.com/">
<types>
<schema attributeFormDefault="qualified" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://object.api.zuora.com/">
<import namespace="http://api.zuora.com/" />
<complexType name="zObject">
<sequence>
<element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull" nillable="true" type="string" />
<element minOccurs="0" maxOccurs="1" name="Id" nillable="true" type="zns:ID" />
</sequence>
</complexType>
<complexType name="Invoice" >
<complexContent>
<extension base="ons:zObject">
<sequence>
<element minOccurs="0" name="AccountId" nillable="true" type="zns:ID" />
<element minOccurs="0" name="AdjustmentAmount" nillable="true" type="decimal" />
<element minOccurs="0" name="PaymentAmount" nillable="true" type="decimal" />
<!--more elements-->
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="Payment" >
<complexContent>
<extension base="ons:zObject">
<sequence>
<element minOccurs="0" name="AccountId" nillable="true" type="zns:ID" />
<element minOccurs="0" name="AccountingCode" nillable="true" type="string" />
<element minOccurs="0" name="Amount" nillable="true" type="decimal" />
<!--more elements-->
</sequence>
</extension>
</complexContent>
</complexType>
<!--more types-->
该技巧似乎是本文所建议的外部绑定文件。 https://community.zuora.com/t5/API/quot-Two-declarations-cause-a-collision-in-the-ObjectFactory/td-p/11265
但是没有代码示例;而且我不知道如何编写这样的绑定文件。
我尝试过:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<jaxb:bindings schemaLocation="zuora.a.77.0.wsdl">
<jaxb:bindings node="//xs:element[@name='PaymentAmount']/xs:complexType">
<jaxb:factoryMethod name="PaymentAmout2"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
但是它似乎太简单了,抛出了
"file:/home/kemkem/Work/repo/asap/tooling-zuora/src/main/resources
/wsdl/zuora.a.77.0.wsdl" is not a part of this compilation.
Is this a mistake for "file:/home/kemkem/Work/repo/asap/tooling-zuora/
src/main/resources/wsdl/zuora.a.77.0.wsdl#types1"
有人有更好的方法吗?
答案 0 :(得分:0)
似乎可以使用以下设置
src / resources / wsdl / zuora.a.77.0.wsdl中的wsdl文件
src / resources / binding.xml:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<jaxb:bindings schemaLocation="wsdl/zuora.a.77.0.wsdl#types1">
<jaxb:bindings node="//xs:element[@name='PaymentAmount']">
<jaxb:factoryMethod name="PaymentAmout2"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Maven CXF插件:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.5</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/zuora.a.77.0.wsdl</wsdl>\
<wsdlLocation>classpath:wsdl/zuora.a.77.0.wsdl</wsdlLocation>
<frontEnd>jaxws21</frontEnd>
<bindingFiles>
<bindingFile>src/main/resources/binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
<defaultOptions>
<autoNameResolution>true</autoNameResolution>
<markGenerated>true</markGenerated>
<asyncMethods />
<bareMethods />
<frontEnd>jaxws21</frontEnd>
<packagenames>
<packagename>com.zuora</packagename>
</packagenames>
</defaultOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>