wsdl中的CXF wsdl2java listwrapper应展开
我目前正在将旧的axis wsclient更新为cxf(jaxb数据绑定)客户端, 现在有了不同之处,wsdl中的CXF wsdl2java listwrapper应展开,java,jaxb,cxf,wsdl2java,cxf-codegen-plugin,Java,Jaxb,Cxf,Wsdl2java,Cxf Codegen Plugin,我目前正在将旧的axis wsclient更新为cxf(jaxb数据绑定)客户端, 现在有了不同之处,list/array是如何处理的 让我用一个例子来解释: wsdl <xsd:complexType name="ArrayOfString"> <xsd:sequence> <xsd:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type=
list/array
是如何处理的
让我用一个例子来解释:
wsdl
<xsd:complexType name="ArrayOfString">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
我的问题是,在cxf中可以这样做吗
我的wsdl的一部分:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://ws611.webservice.adapters.company.de" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws611.webservice.adapters.company.de" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://usermanagement.ws611.webservice.company.de"
xmlns:ns1="http://ws611.webservice.company.de" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws611.webservice.company.de">
<xsd:complexType name="AuthenticationToken">
<xsd:sequence>
<xsd:element minOccurs="0" name="password" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="timestamp" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="username" nillable="true" type="xsd:string"/>
</xsd:sequence>
<xsd:anyAttribute/>
</xsd:complexType>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws611.webservice.adapters.company.de">
<xsd:element name="getAllUsers">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="ns1:AuthenticationToken"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getAllUsersResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="ns2:ArrayOfUser"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://usermanagement.ws611.webservice.company.de">
<xsd:complexType name="ArrayOfUser">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="User" nillable="true" type="ns2:User"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="User">
<xsd:sequence>
<xsd:element minOccurs="0" name="name" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="groups" nillable="true" type="ns2:ArrayOfGroup"/>
</xsd:sequence>
<xsd:anyAttribute/>
</xsd:complexType>
<xsd:complexType name="ArrayOfGroup">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Group" nillable="true" type="ns2:Group"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Group">
<xsd:sequence>
<xsd:element minOccurs="0" name="name" nillable="true" type="xsd:string"/>
</xsd:sequence>
<xsd:anyAttribute/>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getAllUsersRequest">
<wsdl:part name="parameters" element="tns:getAllUsers">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getAllUsersResponse">
<wsdl:part name="parameters" element="tns:getAllUsersResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="UserManagementPortType">
<wsdl:operation name="getAllUsers">
<wsdl:input name="getAllUsersRequest" message="tns:getAllUsersRequest">
</wsdl:input>
<wsdl:output name="getAllUsersResponse" message="tns:getAllUsersResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="UserManagementHttpBinding" type="tns:UserManagementPortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getAllUsers">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getAllUsersRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getAllUsersResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UserManagement">
<wsdl:port name="UserManagementHttpPort" binding="tns:UserManagementHttpBinding">
<wsdlsoap:address location="http://localhost:8080/test/webservice/ws611/UserManagement"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
可以让
cxf codegen插件
生成自动隐藏XML元素包装类的模型类
您需要使用以下三种方法:
@xmlementwrapper
注释,它是用于将列表指定为已包装的JAXB注释<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
此配置将在问题中提供的架构上生成以下内容:
CustomParameter.getValues() // returns List<String>
CustomParameter.getValues()//返回列表
请注意,这不会返回
字符串[]
。通过向您的全局绑定添加collectionType=“index”
属性,您可以让cxf codegen插件
使用String[]
而不是列表
,但目前jaxb-xew插件
只支持集合
类型而不支持数组。我尝试了这个插件,但是生成的代码有编译错误,它找不到ArrayFuser
,我用wsdl编辑了我的查询以进行复制,插件删除了ArrayFuser
,但在我的*PortType中,它仍然被使用。@JannisM我更新了答案,说明了如何指定JAXWS绑定文件以确保正确生成端口类型。但是当enableWrapperStyle
为false
时,再次出现了GetAllUsers
和GetAllUsersResponse
的包装,这看起来更糟,然后是另一个,因此没有其他方法可以拥有enableWrapperStyle=true
并且没有列表包装类?@JannisMGetAllUsers
以任何一种方式存在。将enableWrapperStyle
设置为false
会更改UserManagementPortType
以返回带有单个列表输出的GetAllUserResponse
,而不是带有单个列表用户的ArrayFuser
,因此情况不会更糟。是否希望UserManagementPortType.getAllUsers
直接返回列表
?这可能是不可能的。如果UserManagementPortType#getAllUsers
将返回ArrayFuser
,但ArrayOf*
作为类属性应转换为列表,这将是正常的,但这似乎是不可配置的,或者?
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.4</version>
<executions>
<execution>
<id>generate-client</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/sample.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/jaxbBinding.xml</bindingFile>
<bindingFile>${basedir}/src/main/resources/jaxwsBinding.xml</bindingFile>
</bindingFiles>
<extraargs>
<extraarg>-xjc-Xxew</extraarg>
<extraarg>-xjc-Xxew:summary
${project.build.outputDirectory}/../xew-summary.txt
</extraarg>
<extraarg>-xjc-Xxew:instantiate lazy</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.11</version>
</dependency>
</dependencies>
</plugin>
CustomParameter.getValues() // returns List<String>