CXF-Cllient-调用webservices设置超时时间
在调用webservices,如果采用默认超时时间,链接超时30秒,读超时60秒,可能会造成应用出现假死状态,这....对用户来说整个人都不好了吧~所以,有时候定义下超时的时间,还是很有必要的哈!!!
CXF RESTFul style 乱流哈~当然,本篇也是立于此调用方式来设置超时时间,具体内容如下,结合spirng+apache cxf,当采用proxy方式,即<jaxrs:client>,可使用apache-http-configuration 标签<http-conf:conduit> 来实现对全局 or 独立的方法设置超时
<?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:jaxrs="http://cxf.apache.org/jaxrs"
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-3.0.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<!-- 默认conduit, 链接超时10秒,读超时30秒 -->
<http-conf:conduit name="*.http-conduit">
<http-conf:client ConnectionTimeout="10000"
ReceiveTimeout="30000" />
</http-conf:conduit>
<!-- 针对单个Ws服务设置超时时间 -->
<jaxrs:client id="flightInfoWService" address="http://10.92.2.80:9999"
serviceClass="com.csair.external.cod.service.FlightInfoWService"
inheritHeaders="true">
<jaxrs:headers>
<entry key="authorization" value="COD_WSAMMS,AMMS"></entry>
</jaxrs:headers>
</jaxrs:client>
<!--<http-conf:conduit name=".*/route/api/v1/td/fltinfo/core_kv/">
ConnectionTimeout 连接时间,ReceiveTimeout 接收数据传输时间
<http-conf:client ConnectionTimeout="1" ReceiveTimeout="1"/>
</http-conf:conduit> -->
</beans>
<http-conf:conduit> 属性说明,
- ConnectionTimeout(连接请求超时时间),默认30s-单位(毫秒)
- RecevieTimeout(数据传输超时时间),默认60s-单位(毫秒)
- name:指定哪个方法需要启用超时时间设置,如name="*.http-conduit",表示全局有效
转载至:http://blog.csdn.net/wxyfighting/article/details/9281411