使用wsdl2java编写webservice客户端

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为配置文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值