cxf 动态调用webservices 接口

添加需要的依赖:

<!-- WebService 框架-->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>19.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.2.5</version>
            <scope>compile</scope>
        </dependency>

实现方法:

//wsdlUrl   wsdl地址
  String wsdlUrl = "";
  String message = ""
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = null;
        try {
            client = dcf.createClient(wsdlUrl);
            System.out.println(client + "测试打印输出客户端----------------------------------------------------");
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (client == null) {
            throw new NullPointerException();
        }
        HTTPConduit conduit = null;
        if (client.getConduit() != null) {
            conduit = (HTTPConduit) client.getConduit();
        }
        System.out.println(client + "测试打印输出客户端----------------------------------------------------");
        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setConnectionTimeout(30000); //连接超时时间
        policy.setReceiveTimeout(60000);//请求超时时间.
        if (conduit == null) {
            throw new NullPointerException();
        }
        conduit.setClient(policy);
        Object[] o = new Object[2];
        try {
            o = client.invoke("Services", message);
        }catch (Exception e){
            System.out.println("++++++++++++++++"+e.getMessage());
        }
        for (Object o1 : o) {
            System.out.println(o1 + "测试打印输出返回值----------------------------------------------------");
        }

连接的时候发现一个问题,还没有找到原因,同一个定时任务调用两次这个方法,第二次会报错。只调用一次就很正常。想不通

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值