1、安装apache-cxf插件,使用wsdl2java命令。
webservice--CXF介绍及安装配置_cxf-2.75-CSDN博客
1、获取wsdl文件,生成一个已wsdl为后缀名的文件
2、cmd进入编辑环境,进入项目的项目的java文件夹下面
3、运行wsdl命令,生成java文件
wsdl2java -encoding utf-8 -p com.suyun.rfts.modules.material.cxf.receive -d ./ -all C:/Users/xionglang/Desktop/test.wsdl
-p指的是在哪个包下面生成文件,-all指的是哪个wsdl文件的路径。
4、判断代码中为null的对象是否存在,为null就需要new一个对象
5、修改wsdl的IP路径为可配置
if (url == null) {
Source wsdl = new StreamSource("http://" + WsdlConstant.WSDL_IP_PORT + "/sap/bc/srt/wsdl/flv_10002A111AD1/bndg_url/sap/bc/srt/rfc/sap/z_rfc_rfts_001/300/z_rfc_rfts_001_300_2/z_rfc_rfts_001_300_2?sap-client=300");
try {
url = wsdl.getSystemId() == null ? null : HttpUtil.getEncodedURL(wsdl.getSystemId());
} catch (MalformedURLException e) {
}
}
public static URL getEncodedURL(String urlStr) throws MalformedURLException {
URL url = new URL(urlStr);
String scheme = String.valueOf(url.getProtocol()).toLowerCase();
if (!scheme.equals("http") && !scheme.equals("https")) {
return url;
} else {
try {
return new URL(url.toURI().toASCIIString());
} catch (URISyntaxException var5) {
MalformedURLException malformedURLException = new MalformedURLException(var5.getMessage());
malformedURLException.initCause(var5);
throw malformedURLException;
}
}
}
WsdlConstant.WSDL_IP_PORT变量为静态对象
/**
* wsdl的IP和端口
*/
String WSDL_IP_PORT = PropertiesConfig.getValue("wsdl.sap.ip");
private static Properties properties = null;
public static Properties getProperties() {
try {
properties.load(PropertiesConfig.class.getClassLoader().getResourceAsStream("application.properties"));
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
public final static String getValue(String key) {
if (properties == null) {
properties = new Properties();
getProperties();
}
return properties.getProperty(key);
}
application.properties为配置文件。