背景:
在使用WebService的時候,我們可能需要一個備份的WebService服務器.一旦主服務器down了,我們可以使用備份的服務器.那么這里就需要對客服端連接服務器的時間做一個修改.
在Spring+CXF的WebService環境下,客戶端有兩個時間屬性是可配置的,分別是ConnectionTimeout和ReceiveTimeout.
ConnectionTimeout--WebService以TCP連接為基礎,這個屬性可以理解為tcp的握手時的時間設置,超過設置的時間長則認為是連接超時.以毫秒為單位,默認是30000毫秒,即30秒.
ReceiveTimeout -- 這個屬性是發送WebService的請求后等待響應的時間,超過設置的時長就認為是響應超時.以毫秒為單位,默認是60000毫秒,即60秒.
設置的例子:
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屬性,指定設置生效的服務,如例子中,只對服務名為{http://impl.service.product.sww.com/}ProjectService的服務生效.
使用下面的設置則會對所有服務生效
<http-conf:conduit name="*.http-conduit">

</http-conf:conduit>

更詳細的配置請參考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.