Weservice客户端中设置超时时间

一、前言
在IDEA中创建完webservice后,就可以发起请求了,但是没有设置设置超时时间,网上查了很多资料,关于这方面的比较少,先总结下来,代码经过了生产检验。
二、代码
1)依赖

<dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-rt-transports-http</artifactId>
   <version>3.3.3</version>
</dependency>
<dependency>
   <groupId>org.apache.cxf</groupId>
   <artifactId>cxf-rt-frontend-jaxws</artifactId>
   <version>3.3.3</version>
</dependency>
		// webServiceUrl为请求的webservice地址
		CallServiceFactory.setURL(webServiceUrl);
        CallServiceFactory factory = new CallServiceFactory();
        CallService callService = factory.getCallServicePort();
        
        // 连接参数设定
        Client proxy = ClientProxy.getClient(callService);
        HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();
       
        // 连接超时时间
        policy.setConnectionTimeout(webServiceConfig.getConnectionTimeout());
        // 请求超时时间,设置太短会出现核心还没返回就请求异常
        policy.setReceiveTimeout(webServiceConfig.getReceiveTimeout());
        conduit.setClient(policy);
        // 获取返回结果
         callResult = callService.invoke(args1, args2, args3, args4, args5);

连接超时时间和请求超时时间我都是配置在了配置文件中,自行设定。
如何在IDEA中生成webservice客户端,可以参看我的博客,地址:
在IDEA中生成webservice客户端

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵喵@香菜

感谢观众老爷送的一发火箭!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值