java - 为什么 Maven 生成具有 5 个参数而不是 wsdl 参数的方法?

标签 java maven wsdl code-generation

我正在使用 maven 和 Java 11。我正在从 wsdl 生成类。我希望看到这个

@WebMethod(operationName = "CheckDataBox")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@WebResult(name = "CheckDataBoxResponse", targetNamespace = "http://isds.czechpoint.cz/v20", partName = "parameter")
public TCheckDBOutput checkDataBox(
        @WebParam(partName = "parameter", name = "CheckDataBox", targetNamespace = "http://isds.czechpoint.cz/v20")
                TIdDbInput parameter
);
但它会产生这个
@WebMethod(operationName = "CheckDataBox")
@RequestWrapper(localName = "CheckDataBox", targetNamespace = "http://isds.czechpoint.cz/v20", className = "cz.czechpoint.isds.v20.db.TIdDbInput")
@ResponseWrapper(localName = "CheckDataBoxResponse", targetNamespace = "http://isds.czechpoint.cz/v20", className = "cz.czechpoint.isds.v20.db.TCheckDBOutput")
public void checkDataBox(
        @WebParam(name = "dbID", targetNamespace = "http://isds.czechpoint.cz/v20")
                String dbID,
        @WebParam(name = "dbApproved", targetNamespace = "http://isds.czechpoint.cz/v20")
                Boolean dbApproved,
        @WebParam(name = "dbExternRefNumber", targetNamespace = "http://isds.czechpoint.cz/v20")
                String dbExternRefNumber,
        @WebParam(name = "dbState", targetNamespace = "http://isds.czechpoint.cz/v20", mode = WebParam.Mode.OUT)
                Holder<Integer> dbState,
        @WebParam(name = "dbStatus", targetNamespace = "http://isds.czechpoint.cz/v20", mode = WebParam.Mode.OUT)
                Holder<TDbReqStatus> dbStatus);
我在用
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>javax.jws</groupId>
    <artifactId>javax.jws-api</artifactId>
    <version>1.1</version>
</dependency>
...

<build>
    ...
    <plugins>
        ...
        <plugin>
            <!--groupId>com.sun.xml.ws</groupId-->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <!--version>2.3.2</version-->
            <version>2.6</version>
            <executions>
                <execution>
                    <id>db</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <keep>true</keep>
                        <wsdlFiles>
                            <wsdlFile>${basedir}/src/main/resources/wsdl/db_search.wsdl</wsdlFile>
                            <wsdlFile>${basedir}/src/main/resources/wsdl/db_access.wsdl</wsdlFile>
                        </wsdlFiles>
                        <packageName>cz.czechpoint.isds.v20.db</packageName>
                        <sourceDestDir>${project.build.directory}/generated-sources/wsdl/db</sourceDestDir>
                    </configuration>
                </execution>
                <execution>
                    <id>dm</id>

                    <phase>process-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <keep>true</keep>
                        <wsdlFiles>
                            <wsdlFile>${basedir}/src/main/resources/wsdl/dm_info.wsdl</wsdlFile>
                            <wsdlFile>${basedir}/src/main/resources/wsdl/dm_operations.wsdl</wsdlFile>
                        </wsdlFiles>
                        <packageName>cz.czechpoint.isds.v20.dm</packageName>
                        <sourceDestDir>${project.build.directory}/generated-sources/wsdl/db</sourceDestDir>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
wsdl 文件可以在这里找到 https://github.com/dfridrich/CzechDataBox/tree/master/Resources (这是来自不同人的不同项目,但我使用的是相同的 wsdls。)
为什么不使用一个参数生成,我需要做些什么来实现它?

最佳答案

wsimport决定如何使用 enableWrapperStyle 处理参数配置。您可以遵循两种方法来避免使用更多参数而不是单个参数。
选项 1. 使用绑定(bind)文件
您不需要更新 WSDL 文件。告诉 wsimport如何处理方法参数。
创建一个名为 binding.xml 的文件进入 src/main/resources/wsdl .
绑定(bind).xml

<bindings
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns="http://java.sun.com/xml/ns/jaxws">
    <!-- Disable default wrapper style -->
    <enableWrapperStyle>false</enableWrapperStyle>
</bindings>
更新您的 pom.xml用下面的脚本。有一个额外的步骤是 bindingFiles元素。
pom.xml
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>db</id>
            <phase>process-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <keep>true</keep>
                <wsdlFiles>
                    <wsdlFile>${basedir}/src/main/resources/wsdl/db_search.wsdl</wsdlFile>
                    <wsdlFile>${basedir}/src/main/resources/wsdl/db_access.wsdl</wsdlFile>
                </wsdlFiles>
                <bindingFiles>
                    <bindingFile>${project.basedir}/src/main/resources/binding.xml</bindingFile>
                </bindingFiles>
                <packageName>cz.czechpoint.isds.v20.db</packageName>
                <sourceDestDir>${project.build.directory}/generated-sources/wsdl/db</sourceDestDir>
            </configuration>
        </execution>
        <execution>
            <id>dm</id>
            <phase>process-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <keep>true</keep>
                <wsdlFiles>
                    <wsdlFile>${basedir}/src/main/resources/wsdl/dm_info.wsdl</wsdlFile>
                    <wsdlFile>${basedir}/src/main/resources/wsdl/dm_operations.wsdl</wsdlFile>
                </wsdlFiles>
                <bindingFiles>
                    <bindingFile>${project.basedir}/src/main/resources/binding.xml</bindingFile>
                </bindingFiles>
                <packageName>cz.czechpoint.isds.v20.dm</packageName>
                <sourceDestDir>${project.build.directory}/generated-sources/wsdl/db</sourceDestDir>
            </configuration>
        </execution>
    </executions>
</plugin>
引用:wsimport: Disable Wrapper Style
选项 2. 更改 Wsdl 文件
在您的每个 WSDL 文件中插入下面的 XML 定义。添加此定义后,该方法的参数将只是单个输入参数,而不是所有参数。
    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
    </jaxws:bindings>
示例:db_search.wsdl(粘贴到所有 wsdl 文件)
<definitions name="ISDS_db" targetNamespace="http://isds.czechpoint.cz/v20" 
                                  xmlns="http://schemas.xmlsoap.org/wsdl/" 
                                  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
                                  xmlns:tns="http://isds.czechpoint.cz/v20">

    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
    </jaxws:bindings>

    <types>
      <xs:schema targetNamespace="http://isds.czechpoint.cz/v20">
        <xs:include schemaLocation="IsdsStat.xsd" />
      </xs:schema>
    </types>
    ....

关于java - 为什么 Maven 生成具有 5 个参数而不是 wsdl 参数的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65508885/

相关文章:

Java抽象变量(父类(super class)使用子类的String)

java - 配置 log4j 发送邮件

java - 如何预安装 Eclipse m2e 配置器(生命周期配置未涵盖的插件执行)

如果插件在 pluginManagement 下定义,maven 目标将无法正确执行

java - 当将项目的所有访问修饰符更改为 public 时,字节码中项目的语义是否会发生变化?

java - 停止方法不起作用

java - Maven 在 Linux 上找不到编译器

java - 如何更改从 wsimport.exe 生成的代码的注释语言

java - 如何从 Java 验证 WSDL URL 是否已启动并正在运行?

ruby - 将 savon 与 exacttarget 的 Web 服务结合使用