批量下载wsdl文件
Posted tower888
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量下载wsdl文件相关的知识,希望对你有一定的参考价值。
webservice soap接口, 下面子接口方法比较多时,可以使用此代码 从服务端下载wsdl文件
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
public class GetWsdlFile {
public static void main(String[] args) {
String writeFileDir = "C:/Users/zzz/Desktop/wsdl";
String url = "http://127.0.0.1:18080/MySOAP/services";
if (!FileUtil.exist(writeFileDir)) {
FileUtil.mkdir(writeFileDir);
}
String content = HttpUtil.get(url);
String regex = ".*href=\\"(.*)\\"><i>.*";
List<String> list = new ArrayList<>();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
while (m.find()) {
String s = m.group(1);
System.out.println("======" + s);
list.add(s);
}
for (String wsdlAddr : list) {
// http://127.0.0.1:18080/MySOAP/services/x?wsdl
int index = wsdlAddr.lastIndexOf("/");
String fileName = wsdlAddr.substring(index + 1).replace("?", ".");
String xml = HttpUtil.get(wsdlAddr);
System.out.println(xml);
String file = writeFileDir + "/" + fileName;
System.out.println("write to file: " + file);
FileUtil.writeString(xml, file, "UTF-8");
}
}
}
以上是关于批量下载wsdl文件的主要内容,如果未能解决你的问题,请参考以下文章