为什么maven用5个参数而不是wsdl中的一个参数来生成方法?

92vpleto  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(316)

我正在使用maven和java11。我正在从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 (不同的人的观点不同,但我使用的是相同的wsdl。)
为什么不生成一个参数,我需要做些什么来实现它?

o8x7eapl

o8x7eapl1#

wsimport 决定如何使用 enableWrapperStyle 配置。您可以遵循两种方法来避免使用更多参数而不是单个参数。

方案1。带绑定文件

您不需要更新wsdl文件。告诉警察 wsimport 如何处理方法参数。
创建一个名为 binding.xml 进入 src/main/resources/wsdl .
绑定.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:禁用 Package 器样式

方案2。更改wsdl文件

在每个wsdl文件中插入下面的xml定义。添加此定义后,方法的参数将仅是一个输入参数,而不是所有参数。

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

示例:db\u 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>
    ....

相关问题