wsdl 2 java-如何强制 Package 的响应返回类型,而不是使用 Package 在持有者的参数?

os8fio9y  于 11个月前  发布在  Java
关注(0)|答案(2)|浏览(108)

使用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设置为falsetrue都没有改变任何东西。下面是我的配置(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",
        )
    )
}


sessiontoken都声明为wsdlsoap:header,这会对生成的Java代码产生影响吗?

vcirk6k6

vcirk6k61#

最简单的方法-将bareMethods参数传递给wsdl 2 java:

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",
        "-bareMethods",
        "https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
    )
)}

字符串

e4yzc0pl

e4yzc0pl2#

bindings.xml中,将xmlns属性更改为https://jakarta.ee/xml/ns/jaxws

<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">
 +       xmlns="https://jakarta.ee/xml/ns/jaxws">
    <enableWrapperStyle>false</enableWrapperStyle>
</bindings>

字符串
那么<enableWrapperStyle>false</enableWrapperStyle>就可以了。

相关问题