build.gradle文件中有下一个任务,可以下载WSDL并生成类。
我尝试下载的WSDL已通过基本身份验证进行了身份验证。我有用户名和密码凭据。
如何设置此任务以包含用户名和密码?
我已从https://spring.io/guides/gs/consuming-web-service/
复制了此任务task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = 'https://IP/path/wsdl.asmx?WSDL'
outputs.dir classesDir
doLast() {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
xjc(destdir: sourcesDir, schema: schema,
package: "package.wsdl") {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath) {
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}
copy(todir: classesDir) {
fileset(dir: sourcesDir, erroronmissingdir: false) {
exclude(name: "**/*.java")
}
}
}
}
}
预先感谢
答案 0 :(得分:0)
我不确定ant的 XJCTask 是否支持基本身份验证来检索源Wsdl。在您的情况下,我将分两步进行:
一些准则:
下载任务
从网络中检索Wsdl的虚拟示例(即使此Web服务器不需要它,也具有基本身份验证)
ext {
wsdlSrcUrl = 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'
wsdlLocalPath = "$buildDir/BLZService.wsdl"
wsdlUser= 'testUser'
wsdlPassword = 'userPass'
}
task downloadWsdsl {
doLast {
file(buildDir).mkdir()
ant.get(src: wsdlSrcUrl, dest: wsdlLocalPath, username: wsdlUser, password: wsdlPassword)
}
}
Codegen任务
此任务取决于 downloadWsdsl 任务
task genJaxb {
dependsOn downloadWsdsl
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = wsdlLocalPath
outputs.dir classesDir
doLast() {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
xjc(destdir: sourcesDir, schema: schema, package: "hello.wsdl") {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath) {
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}
copy(todir: classesDir) {
fileset(dir: sourcesDir, erroronmissingdir: false) {
exclude(name: "**/*.java")
}
}
}
}
}