背景:
在使用WebService的時候,我們可能需要一個備份的WebService服務(wù)器.一旦主服務(wù)器down了,我們可以使用備份的服務(wù)器.那么這里就需要對客服端連接服務(wù)器的時間做一個修改.
在Spring+CXF的WebService環(huán)境下,客戶端有兩個時間屬性是可配置的,分別是ConnectionTimeout和ReceiveTimeout.
ConnectionTimeout--WebService以TCP連接為基礎(chǔ),這個屬性可以理解為tcp的握手時的時間設(shè)置,超過設(shè)置的時間長則認(rèn)為是連接超時.以毫秒為單位,默認(rèn)是30000毫秒,即30秒.
ReceiveTimeout -- 這個屬性是發(fā)送WebService的請求后等待響應(yīng)的時間,超過設(shè)置的時長就認(rèn)為是響應(yīng)超時.以毫秒為單位,默認(rèn)是60000毫秒,即60秒.
設(shè)置的例子:
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
xmlns:jee="http://www.springframework.org/schema/jee"
5
xmlns:jaxws="http://cxf.apache.org/jaxws"
6
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
7
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
8
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
9
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
10
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd ">
11
<http-conf:conduit name="{http://impl.service.product.super.com/}ProjectService.http-conduit">
12
<http-conf:client ConnectionTimeout="10000" ReceiveTimeout="20000"/>
13
</http-conf:conduit>
14
</beans>
15
這里需要注意的有幾個地方:
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屬性,指定設(shè)置生效的服務(wù),如例子中,只對服務(wù)名為{http://impl.service.product.sww.com/}ProjectService的服務(wù)生效.
使用下面的設(shè)置則會對所有服務(wù)生效
<http-conf:conduit name="*.http-conduit">

</http-conf:conduit>

更詳細(xì)的配置請參考CXF官方文檔:
http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html
Let life be beautiful like summer flowers and death like autumn leaves.