我想与Astrinet API一起工作。它的一个WSDL文件在这里:
affilinet counltervice.wsdl
我使用此Maven插件生成源:
jaxb maven插件
我的pom.xml插件配置:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.logon</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/Logon.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/PublisherInbox.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>schema3-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>webservices.framework.affilinet.inbox</generatePackage>
<schemas>
<schema>
<url>https://api.affili.net/V2.0/AccountService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
所以,在编译此事时,我会收到一个错误:
com.sun.istack.SAXParseException2; systemId: https://api.affili.net/V2.0/AccountService.svc?wsdl; lineNumber: 1; columnNumber: 2127; Two declarations cause a collision in the objectFactory class.
但是如何使用URL的WSDL文件修复此操作?
示意图不接受WSDL文件..
编辑:完整日志:
[ERROR] Error while generating code.Location [ https://api.affili.net/V2.0/AccountService.svc?wsdl{1,6200}].
com.sun.istack.saxparseexception2;SystemID:https://api.affili.net/v2.0/accountservice.svc?wsdl;亚麻数:1;Columnnumber:6200;这是另一个声明。
如果您有两个相互冲突的定义,通常会发生这种情况。由于格式不佳,因此很难判断您的WSDL确切出错。但通常这将是两个元素,这些元素在转换为Java后获得相同的方法名称。
您通常可以通过绑定自定义来解决此问题。这是一个例子:
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings
schemaLocation="http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd"
node="/xs:schema">
<jaxb:bindings node="xs:element[@name='_Appearance']">
<jaxb:factoryMethod name="AAppearance"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
因此,您要做的就是找出确切导致问题的是什么,写并应用绑定。我要做的第一件事是下载WSDL,将其格式化为人类可读并在本地进行编译。这应该给出一个明确的指针,以便在哪些部分引起问题。
面对同一问题,我有多个模式,很难确定哪些元素会导致碰撞。在添加JAXB绑定后,我能够解析和生成对象捕集类,以提供重复的元素的不同名称。
示例:我将" ID"作为Product.xsd
和CustomerOrder.xsd
中的共同元素之一,因此必须提供共同的绑定。XJB文件。
<jaxb:bindings schemaLocation="../../Common/XSD/Product.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="ProductId" />
</jaxb:bindings>
<jaxb:bindings schemaLocation="../../Common/XSD/CustomerOrder.xsd" node="//xs:element[@name='Id']">
<jaxb:class name="CustomerOrderId" />
</jaxb:bindings>
这是我在 pm.xml
execution
<execution>
<id>Outbound</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
<arg>-XtoString</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>some.package.name</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</schemaDirectory>
<bindingDirectory>${project.basedir}/src/main/resources/Outbound/WSDL</bindingDirectory>
<strict>false</strict>
<bindingIncludes>
<include>*.xjb</include>
</bindingIncludes>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2.basics.version}</version>
</plugin>
</plugins>
</configuration>
</execution>