使用wsdl2java
工具生成客户端类,我似乎无法强制将Web Service响应 Package 在返回类型中-返回类型始终是void
,并生成 Package 在Holder
s中的OUT
参数。Auth.java
自动生成的客户端接口如下所示:
@WebService(targetNamespace = "http://xml.kamsoft.pl/ws/auth", name = "Auth")
@XmlSeeAlso({pl.kamsoft.xml.ws.common.ObjectFactory.class, pl.kamsoft.xml.ws.kaas.login_types.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface Auth {
// [...] - `logout`, `changePassword`, `changePasswordLog` methods
@WebMethod(action = "login")
public void login(
@WebParam(partName = "request", name = "login", targetNamespace = "http://xml.kamsoft.pl/ws/kaas/login_types")
pl.kamsoft.xml.ws.kaas.login_types.LoginRequest request,
@WebParam(partName = "response", mode = WebParam.Mode.OUT, name = "loginReturn", targetNamespace = "http://xml.kamsoft.pl/ws/kaas/login_types")
jakarta.xml.ws.Holder<java.lang.String> response,
@WebParam(partName = "session", mode = WebParam.Mode.OUT, name = "session", targetNamespace = "http://xml.kamsoft.pl/ws/common", header = true)
jakarta.xml.ws.Holder<pl.kamsoft.xml.ws.common.Session> session,
@WebParam(partName = "token", mode = WebParam.Mode.OUT, name = "authToken", targetNamespace = "http://xml.kamsoft.pl/ws/common", header = true)
jakarta.xml.ws.Holder<pl.kamsoft.xml.ws.common.AuthToken> token
) throws pl.kamsoft.wsdl.common.AuthenticationExceptionMsg, pl.kamsoft.wsdl.common.ServerExceptionMsg, PassExpiredExceptionMsg, pl.kamsoft.wsdl.common.AuthTokenExceptionMsg, pl.kamsoft.wsdl.common.InputExceptionMsg, pl.kamsoft.wsdl.common.AuthorizationExceptionMsg;
}
字符串
最小示例(使用Gradle配置的build.gradle.kts
文件):
plugins {
java
id("com.yupzip.wsdl2java") version "3.0.0"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.cxf:cxf-rt-frontend-jaxws:4.0.0")
implementation("org.apache.cxf:cxf-rt-transports-http-hc5:4.0.0")
wsdl2java("com.sun.xml.bind:jaxb-impl:4.0.1")
wsdl2java("org.apache.cxf.xjc-utils:cxf-xjc-runtime:4.0.0")
wsdl2java("jakarta.xml.ws:jakarta.xml.ws-api:4.0.0")
wsdl2java("com.sun.xml.ws:rt:4.0.0")
wsdl2java("org.jvnet.jaxb2_commons:jaxb2-namespace-prefix:2.0")
wsdl2java("codes.rafael.jaxb2_commons:jaxb2-basics-runtime:3.0.0")
wsdl2java("codes.rafael.jaxb2_commons:jaxb2-basics:3.0.0")
}
wsdl2java {
wsdlDir = file("$projectDir/src/main/resources/")
includeJava8XmlDependencies = false
cxfVersion = "4.0.0"
cxfPluginVersion = "4.0.0"
wsdlsToGenerate = listOf(
listOf(
"-wsdlLocation", "https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
"-autoNameResolution",
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
)
)
}
型
如何强制wsdl2java
工具生成Auth#login
调用时返回哪个示例的LoginResponse
类?
我尝试包含绑定文件(bindings.xml
):
<bindings
wsdlLocation="https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://java.sun.com/xml/ns/jaxws">
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
型
但是将enableWrapperStyle
设置为false
或true
都没有改变任何东西。下面是我的配置(build.gradle.kts
):
wsdl2java {
wsdlDir = file("$projectDir/src/main/resources/")
includeJava8XmlDependencies = false
cxfVersion = "4.0.0"
cxfPluginVersion = "4.0.0"
wsdlsToGenerate = listOf(
listOf(
"-b", "$projectDir/src/main/resources/wsdl/bindings.xml",
"-wsdlLocation", "https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
"-autoNameResolution",
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
)
)
}
型session
和token
都声明为wsdlsoap:header
,这会对生成的Java代码产生影响吗?
2条答案
按热度按时间vcirk6k61#
最简单的方法-将bareMethods参数传递给wsdl 2 java:
字符串
e4yzc0pl2#
在
bindings.xml
中,将xmlns属性更改为https://jakarta.ee/xml/ns/jaxws
字符串
那么
<enableWrapperStyle>false</enableWrapperStyle>
就可以了。