CXF:wsdl2java错误 - WSDL包含重复名称
问题描述:
我试图从第三方使用SOAP Web服务。我有一个maven项目,我正试图使用cxf-codegen-plugin在提供的WSDL上使用wsdl2java运行代码生成。CXF:wsdl2java错误 - WSDL包含重复名称
WSDL的问题是在同一个复杂类型中有一个元素和一个具有相同名称的属性。所以,我得到以下错误试图运行mvn干净安装时:
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片段:
<?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全新安装' 与此设置中,我得到以下错误:
XPath evaluation of ".//s:attribute[@name='SomeId']" results in empty target node
我已经将节点路径改为指向元素,并且还使用了完整的节点路径结构,例如节点=“wsdl:定义/ wsdl:类型....”但我不断收到相同的错误。感觉就像我在这里的圈子里一样。
如果有人能够看到我要出错的地方并向我指出这一点,我将不胜感激,因为这是我第一次尝试实施这样的事情。
在此先感谢。
答
所以我最终想到了这一点。原来,jaxb:bindings无法解析节点路径。所以我使用jaxws来解析路径和jaxb来更新属性名称。
工作绑定文件是这样的:
<jaxws:bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:s="http://www.w3.org/2001/XMLSchema" version="2.1">
<jaxws:bindings node=".//s:element[@name='SomeId']">
<jaxb:property name="anotherId" />
</jaxws:bindings>
</jaxws:bindings>