CXF 连接超时与请求超时的设置
来源:互联网 发布:网络中介服务提供商 编辑:程序博客网 时间:2024/05/21 22:57
代码在编译、运行是没问题的,但测试发现如果服务端没有启动或网络环境差,CXF会默认等待一定的时间~~~
则有了客户端调用超时的设置;
方式 1 - 在代码中设置超时:
//这是命令生成的类,该类的实例可当成工厂来使用CXFEtcvRemindInfoServiceImpl factory = new CXFEtcvRemindInfoServiceImpl();//无参的方法,返回的是远程Web Service服务端的代理,服务端不能关闭。CXFEtcvRemindInfoService cxfPort = factory.getCXFEtcvRemindInfoServiceImplPort();Client client = ClientProxy.getClient(cxfPort);client.getOutInterceptors().add(new LoggingInInterceptor());//输出In信息的日志client.getOutInterceptors().add(new LoggingOutInterceptor());//输出Out信息的日志//传参的List<Bean>List<CxfEtcvRemindInfoPushInputParam> inputParams = new ArrayList<CxfEtcvRemindInfoPushInputParam>();CxfEtcvRemindInfoPushInputParam inputParam = new CxfEtcvRemindInfoPushInputParam();inputParam.setDepartureDate("2016-12-09");inputParams.add(inputParam);// 连接参数设定Client proxy = ClientProxy.getClient(cxfPort);HTTPConduit conduit = (HTTPConduit) proxy.getConduit();HTTPClientPolicy policy = new HTTPClientPolicy();// 连接超时时间policy.setConnectionTimeout(10000);// 请求超时时间policy.setReceiveTimeout(10000);conduit.setClient(policy);//调用接口,返回信息List<CxfEtcvRemindInfoPushOutputParam> outputParams = cxfPort.pushEVRemindInfo(inputParams);超时设置核心代码为
// 连接参数设定
Client proxy = ClientProxy.getClient(cxfPort);
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
// 连接超时时间
policy.setConnectionTimeout(10000);
// 请求超时时间
policy.setReceiveTimeout(10000);
conduit.setClient(policy);
方式 2 - 在配置文件中设置超时(百度得到):
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd "> <http-conf:conduit name="{http://impl.service.product.super.com/}ProjectService.http-conduit"> <http-conf:client ConnectionTimeout="10000" ReceiveTimeout="10000"/> </http-conf:conduit> </beans>
这里需要注意的有几个地方:
1:需要指定http-conf名称空间 xmlns:http-conf=http://cxf.apache.org/transports/http/configuration
2:指定模式位置: http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
3:http-conf:conduit中的name属性,指定设置生效的服务,如例子中,只对服务名为{http://impl.service.product.sww.com/}ProjectService的服务生效.
使用下面的设置则会对所有服务生效
<http-conf:conduit name="*.http-conduit">
<http-conf:client……>
</http-conf:conduit>
希望对你有帮助,祝你有一个好心情,加油!
若有错误、不全、可优化的点,欢迎纠正与补充;转载请注明出处!
- CXF 连接超时与请求超时的设置
- HttpClient连接请求超时设置
- HttpClient连接请求超时设置
- CXF客户端设置连接超时时间
- 设置请求超时的时间
- 设置请求超时的时间
- Socket的读取超时与连接超时
- C#中设置Socket连接请求的超时
- c# socket连接请求超时设置
- mysql的连接超时设置
- CXF-WebService设置超时时间
- request 请求超时设置。
- 设置网络请求超时
- Retrofit设置请求超时
- AFN设置请求超时
- 连接超时引起的第二次请求?
- httpClient请求超时的设置以及处理
- 设置Apache的HttpClient请求时间超时
- 编码技巧(一)命名
- linux安装JDK遇到的几个低级问题
- [51nod 1139]奇妙等式的解
- 贪心算法之单源最短路径Dijkstra
- 双网卡
- CXF 连接超时与请求超时的设置
- 228. Summary Ranges
- 利用余弦计算文本相似性
- Spring学习04--注入、依赖、方法注入详解
- Struts2框架的意义
- “结对编程” 实验心得
- php 全局变量global的使用方法
- java连接oracle数据库
- python统计贴吧发帖数(找水王)