【发布时间】:2017-09-14 17:26:35
【问题描述】:
我正在尝试使用来自第 3 方的 SOAP Web 服务。我有一个 maven 项目,我正在尝试使用 cxf-codegen-plugin 在提供的 WSDL 上使用 wsdl2java 运行代码生成。
WSDL 的问题是在同一个复杂类型中存在同名的元素和属性。因此,在尝试运行 mvn clean install 时出现以下错误:
Property "SomeId" is already defined. Use <jaxb:property> to resolve this conflict.
在查看解决此问题的方法后,似乎是添加一个绑定文件来重命名给出错误的属性名称。
我的绑定文件如下所示:
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jxb:bindings node=".//s:attribute[@name='SomeId']">
<jxb:property name="anotherId" />
</jxb:bindings>
</jxb:bindings>
WSDL sn-p:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns=“namespace” xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace=“namespace”>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace=“namespace”>
<s:element name="GetData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="request">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Nbr" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetDataResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetDataResult">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ITEM">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Pty">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name=“SomeId” type="s:string"/>
</s:sequence>
<s:attribute name="SomeId" type="s:string" />
</s:complexType>
(注意:“命名空间”隐藏了公司名称。)
我已经将我的 POM 指向绑定文件:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/a.wsdl</wsdl>
<wsdlLocation>classpath:META-INF/wsdl/a.wsdl</wsdlLocation>
<packagenames>
REMOVED
</packagenames>
<extraargs>
<extraarg>-fe</extraarg>
<extraarg>jaxws21</extraarg>
<extraarg>-autoNameResolution</extraarg>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/META-INF/wsdl/binding.xsd</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
问题:
当我使用此设置运行“mvn clean install”时,我收到以下错误:
XPath evaluation of ".//s:attribute[@name='SomeId']" results in empty target node
我已将节点路径更改为指向元素,并且还使用了完整的节点路径结构,例如node="wsdl:definitions/wsdl:types...." 但我不断收到同样的错误。感觉自己在这里绕圈子。
如果有人能看出我哪里出了问题并指出来,我将不胜感激,因为这是我第一次尝试实现这样的东西。
提前致谢。
【问题讨论】:
标签: java web-services maven soap wsdl2java