【发布时间】:2019-07-10 11:22:58
【问题描述】:
我正在使用 Maven 的 cxf-codegen-plugin 从 wsdl/xsd 文件生成 Java 类(然后基于它们打包一个 jar)。我之所以选择这个插件而不是其他选项,是因为它允许我“动态地”引用文件夹中的所有 wsdl 和 xsd 文件,而不是“静态地”将它们一一写在 <wsdl/> 标签中。
FurtherExtensionOfBaseObj Java 类(在internet.xsd 文件中定义)由MyBarRequest(来自bar.wsdl)和MyZedRequest(来自zed.wsdl)实现,但仅在其@XmlSeeAlso 注释中实现@ 987654331@被引用。
就好像插件只考虑了他在第一个处理的 wsdl 中找到的内容(按字母顺序排列)而不考虑其他内容。 我怎样才能获得插件(或任何其他插件,尽管我喜欢这个)在@XmlSeeAlso 注释中引用所有扩展类?
您可以在https://gitlab.com/t.meledina/xmlseealso-issue-poc 上提取一个完全重现此问题的工作项目
编辑:问题现已解决,存储库现在是下面 Tomas 解决方案的工作示例。
或者,可以使用以下文件列表来重现问题,common.xsd 应该无关紧要,但它是编译所必需的。
common.xsd 文件
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.somehost.com/common/beans" xmlns:beans="http://www.somehost.com/common/beans" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="SomeCommonObj">
<xsd:sequence>
<xsd:element name="woop" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ExtensionOfSomeCommonObj">
<xsd:complexContent>
<xsd:extension base="beans:SomeCommonObj">
<xsd:sequence>
<xsd:element name="moreWoop" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="BaseRequest">
<xsd:sequence>
<xsd:element name="floop" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BaseResponse">
<xsd:sequence>
<xsd:element name="scoop" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AnotherCommonObj">
<xsd:annotation>
<xsd:documentation>whatever</xsd:documentation>
</xsd:annotation>
<xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="ExtensionOfAnotherCommonObj">
<xsd:annotation>
<xsd:documentation>son of whatever</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:AnotherCommonObj">
<xsd:sequence>
<xsd:element minOccurs="1" name="goop" type="xsd:int"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="BarObj">
<xsd:sequence>
<xsd:element name="noop" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
internet.xsd 文件
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.somehost.com/internet/beans" xmlns:tns="http://www.somehost.com/internet/beans" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.somehost.com/common/beans" schemaLocation="common.xsd"/>
<xsd:complexType name="BaseObj">
<xsd:sequence>
<xsd:element name="zeep" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ExtensionOfBaseObj">
<xsd:complexContent>
<xsd:extension base="tns:BaseObj">
<xsd:sequence>
<xsd:element name="moreZeep" type="xsd:int"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SomeOtherObj">
<xsd:sequence>
<xsd:element name="neep" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="YetSomeOtherObj">
<xsd:sequence>
<xsd:element name="geep" type="xsd:dateTime"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="FurtherExtensionOfBaseObj">
<xsd:complexContent>
<xsd:extension base="tns:ExtensionOfBaseObj">
<xsd:sequence>
<xsd:element name="evenMoreZeep" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
bar.wsdl 文件
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="bar" targetNamespace="http://www.somehost.com/internet/bar/" xmlns:beans="http://www.somehost.com/internet/bar/beans/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.somehost.com/internet/bar/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema jaxb:version="2.0" targetNamespace="http://www.somehost.com/internet/bar/beans/" xmlns:common="http://www.somehost.com/common/beans" xmlns:internet="http://www.somehost.com/internet/beans" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<xsd:import namespace="http://www.somehost.com/common/beans" schemaLocation="common.xsd"/>
<xsd:import namespace="http://www.somehost.com/internet/beans" schemaLocation="internet.xsd"/>
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" xmlType="xsd:dateTime"/>
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType name="myBarRequest">
<xsd:complexContent>
<xsd:extension base="internet:FurtherExtensionOfBaseObj">
<xsd:sequence>
<xsd:element minOccurs="0" name="barObjAttuale" type="common:BarObj"/>
<xsd:element name="barObjNuovo" type="common:BarObj"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myBarRequestElement" type="beans:myBarRequest"/>
<xsd:complexType name="myBarResponse">
<xsd:complexContent>
<xsd:extension base="common:BaseResponse">
<xsd:sequence minOccurs="0">
<xsd:element name="barObj" type="common:BarObj"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myBarResponseElement" type="beans:myBarResponse"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="myBarRequest">
<wsdl:part element="beans:myBarRequestElement" name="parameters"/>
</wsdl:message>
<wsdl:message name="myBarResponse">
<wsdl:part element="beans:myBarResponseElement" name="parameters"/>
</wsdl:message>
<wsdl:portType name="barPortType">
<wsdl:operation name="myBar">
<wsdl:input message="tns:myBarRequest"/>
<wsdl:output message="tns:myBarResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="barBinding" type="tns:barPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="myBar">
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="barService">
<wsdl:port binding="tns:barBinding" name="barPort">
<soap12:address location="http://localhost:9080/internet/barService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
zed.wsdl 文件
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="zedService" targetNamespace="http://www.somehost.com/internet/zed/" xmlns:beans="http://www.somehost.com/internet/zed/beans/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://www.somehost.com/internet/zed/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema jaxb:version="2.0" targetNamespace="http://www.somehost.com/internet/zed/beans/" xmlns:common="http://www.somehost.com/common/beans" xmlns:internet="http://www.somehost.com/internet/beans" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<xsd:import namespace="http://www.somehost.com/common/beans" schemaLocation="common.xsd"/>
<xsd:import namespace="http://www.somehost.com/internet/beans" schemaLocation="internet.xsd"/>
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" xmlType="xsd:dateTime"/>
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType name="myZedRequest">
<xsd:complexContent>
<xsd:extension base="internet:FurtherExtensionOfBaseObj">
<xsd:sequence>
<xsd:element minOccurs="1" name="blaap" type="xsd:long"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myZedRequestElement" type="beans:myZedRequest"/>
<xsd:complexType name="myZedResponse">
<xsd:complexContent>
<xsd:extension base="common:BaseResponse">
<xsd:sequence minOccurs="0"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myZedResponseElement" type="beans:myZedResponse"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="myZedRequest">
<wsdl:part element="beans:myZedRequestElement" name="parameters"/>
</wsdl:message>
<wsdl:message name="myZedResponse">
<wsdl:part element="beans:myZedResponseElement" name="parameters"/>
</wsdl:message>
<wsdl:portType name="zedPortType">
<wsdl:operation name="myZed">
<wsdl:input message="tns:myZedRequest"/>
<wsdl:output message="tns:myZedResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="zedBinding" type="tns:zedPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="myZed">
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="zedService">
<wsdl:port binding="tns:zedBinding" name="zedPort">
<soap12:address location="http://localhost:9080/internet/zedService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mytest.mobile</groupId>
<artifactId>mytest-jax-ws</artifactId>
<version>20190707-1950</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.17</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlRoot>src/main/resources/wsdl</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.7</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
提前感谢您的帮助。
【问题讨论】: