为什么 Maven 使用 5 个参数而不是来自 wsdl 的一个参数生成方法?
Why is Maven generating method with 5 parameters instead of one from wsdl?
我正在使用 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. 绑定文件
您不需要更新 WSDL 文件。告诉 wsimport
如何处理方法参数。
在 src/main/resources/wsdl
中创建一个名为 binding.xml
的文件。
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>
使用以下脚本更新您的 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>
....
我正在使用 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. 绑定文件
您不需要更新 WSDL 文件。告诉 wsimport
如何处理方法参数。
在 src/main/resources/wsdl
中创建一个名为 binding.xml
的文件。
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>
使用以下脚本更新您的 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>
....