Why is Maven generating method with 5 parameters instead of one from wsdl?

落花浮王杯 提交于 2021-02-07 09:29:40

问题


I am using maven and Java 11. I am generating classes from wsdl. I expect to see this

@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
);

but it generates this

@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);

I am using

<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>

The wsdl files can be found here https://github.com/dfridrich/CzechDataBox/tree/master/Resources (It is a different poject from different person but I am using same wsdls.)

Why is not generated with one param and what I need to do to achiveve it?


回答1:


wsimport decides how to approach parameters with enableWrapperStyle configuration. You can follow two approaches to avoid more parameters instead of a single parameter.

Option 1. With Binding File

You don't need to update WSDL files. Tell to the wsimport how to process method arguments.

Create a file that is called binding.xml into src/main/resources/wsdl.

binding.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>

Update your pom.xml with below script. There is an extra step that is bindingFiles element.

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>

Reference: wsimport: Disable Wrapper Style

Option 2. Change Wsdl Files

Insert below XML definition in your every WSDL file. Adding this definition, the method's arguments will only be a single input argument instead of all parameters.

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

Example: db_search.wsdl (Paste to all wsdl files)

<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>
    ....


来源:https://stackoverflow.com/questions/65508885/why-is-maven-generating-method-with-5-parameters-instead-of-one-from-wsdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!