1. 程式人生 > >CXF WebService 客戶端設定超時時間

CXF WebService 客戶端設定超時時間

本文主要介紹CXF WebService 客戶端如何設定超時時間,以及相關引數的介紹。

在使用WebService時,出現了超時的異常,如下。

警告: Interceptor for {http://www.idc.com/idc/idc.wsdl}SouthBaseService#{http://www.idc.com/idc/idc.wsdl}SyncVmInfo has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
...
Caused by: java.net
.SocketTimeoutException: SocketTimeoutException invoking http://127.0.0.1:8081/njrs/SouthBaseWS: Read timed out ... Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:152) at java.net
.SocketInputStream.read(SocketInputStream.java:122) at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) at java.io.BufferedInputStream.read(BufferedInputStream.java:334) at sun.net.www.http.HttpClient.parseHTTPHeader
(HttpClient.java:689) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1324) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2165) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2134) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1988) ... 105 more

最初的想法是覺得肯定有地方是可以設定這麼一個超時時間的,但是卻苦苦找不到設定的地方,最終經過各種折騰,Google之百度之,找到了解決辦法。

Using WebService, we usually set in the client request timeout limit in order to avoid long time to connect to the server is unavailable. CXF environment, the client can be configured through two properties timeout limit:

在使用網路服務時,通常需要為客戶端設定請求超時時間,以避免長時間的去連線不可用的伺服器。在CXF環境中,客戶端可以通過兩個引數配置超時限制:

  • The ConnectionTimeout: WebService based TCP connection, this property can be understood as TCP handshake time settings, exceeds the time that it is the connection timeout in milliseconds, the default is 30000 milliseconds, or 30 seconds.
  • ConnectionTimeout: WebService是基於TCP連線的,因此這個屬性可以理解為設定TCP握手時間,若超出這個時間就認為連線超時。預設的時間單位是毫秒,預設設定是30000毫秒,即30秒。

  • ReceiveTimeout: this property WebService request is sent to wait for a response time exceeds the length of time that it is the response timeout in milliseconds, the default is 60000 milliseconds, or 60 seconds.

  • ReceiveTimeout: 這個屬性表示傳送WebService請求後所等待響應的時間,若超過設定的時間則認為超時。預設的時間單位是毫秒,預設設定是60000毫秒,即60秒。

Here are two ways to configure the client:
下面有兩種方法可以在客戶端進行配置:

In the spring configuration file settings.
- 在spring配置檔案中進行配置。

<?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="{WSDL Namespace}portName.http-conduit">       
      <http-conf:client ConnectionTimeout="10000" ReceiveTimeout="20000"/>      
   </http-conf:conduit>       
</beans>    

It should be noted there are several places:
1, we need to specify the http-conf namespace: xmlns: http-conf =
2, the location of the specified pattern:
Http-conf: Conduit name attribute to specify service settings to take effect. by the service namespace in the WSDL port name. “http-conduit”, the name attribute, such as the {} HelloWorld.http in-conduit. If the name attribute is set to “http-conduit”, will be effective for all services.

如下幾點需要注意:
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屬性,指定設定生效的服務。name屬性由service的namespace、WSDL中的 port name和”.http-conduit”組成,如{http://apache.org/hello_world}HelloWorld.http- conduit。如果將name屬性設定為“*.http-conduit”,則會對所有服務生效。

Java code to be set.
- 使用Java程式碼設定:

Client client = ClientProxy.getClient (port);
HTTPConduit http = (HTTPConduit) client.getConduit();
To = new HTTPClientPolicy (HTTPClientPolicy httpClientPolicy);
httpClientPolicy.setConnectionTimeout (36000);
httpClientPolicy.setAllowChunking (false);
httpClientPolicy.setReceiveTimeout (32000);
http.setClient (httpClientPolicy);

Server-side set spring code is as follows:
- 伺服器端的spring程式碼配置如下:

<! - On the server side to set the response timeout limit, now is the default value of 30 seconds ->
<http-conf:destination name="*.http-conduit">
<http-conf:server ReceiveTimeout="30000" />
</ Http-conf: destination>

如果覺得有用,歡迎關注我的微信,有問題可以直接交流:

你的關注是對我最大的鼓勵!

相關推薦

CXF WebService 客戶設定超時時間

本文主要介紹CXF WebService 客戶端如何設定超時時間,以及相關引數的介紹。 在使用WebService時,出現了超時的異常,如下。 警告: Interceptor for {http://www.idc.com/idc/idc.wsdl}

webservice java客戶設定超時時間

//webservice例項 moreLikeThisHBaseWebServiceServiceStub = new MoreLikeThisHBaseWebServiceServiceStub(url); //設定超時時間 Options options = moreLikeThisHBaseW

wsdl 檔案生產webservice 客戶(jax-ws) ,介面超時設定

1.  首先 把需要呼叫的方法的類(clientToServiceClas)進行如下轉換:       BindingProvider bindingP=(BindingProvider)clientToServiceClass; 2. 設定連線超時時間,使用Bin

CXF 呼叫webservice客戶步驟

1、通過cxf用wsdl生成java客戶端檔案 下載apache的cxf檔案下本地,再用wsdl2java命令生成,並copy java到相應的目錄 2、客戶端程式碼 @Test public void q30100(){ //設定請求引數 DTSaleA

根據cxf生成webservice客戶程式碼

官方cxf下載地址:http://cxf.apache.org/download.html 在下載cxf bin目錄下命令列方式執行 wsdl2java -encoding utf8 wsdl地址 -p 也就是package 對應java中的包 -d 輸入目錄,生成.java檔案

TCP服務設定超時時間

socket的setSoTimeOut() 因為呼叫ServerSocket類的accept()方法和Socket輸入流的read()方法時會引起執行緒阻塞,所以應該用 setSoTimeout()方法設定超時,預設的設定是0,即超時永遠不會發生。超時的判斷是累計式

CXF動態客戶呼叫JDK自帶Webservice安全校驗

        專案中有個需求,需要使用CXF動態客戶端呼叫webservice服務端,這個服務端是JDK自帶的webservice釋出的,而且我們需要在呼叫時傳入使用者名稱和密碼。網上CXF客戶端和服務端配套使用webservice的方法很多,這裡不再贅述,這裡主要講下我

通過cxf JaxWsDynamicClientFactory進行WebService 客戶呼叫

通過JaxWsDynamicClientFactory進行WebService 客戶端呼叫的一個好處就是隻需要知道了WSDL地址就行了,不需要手動生成任何程式碼,這樣,如果需要呼叫多個WebService服務的話,只需要建立多個Client即可,不用考慮傳統方式(生成程式碼)

服務使用CXF框架客戶使用Axis2框架的webservice實現方案

背景:       執行在兩臺獨立伺服器上的兩個web服務,其中一個web服務需要訪問另一個web服務的業務方法。但是兩個服務各自的執行環境不同,一個服務執行在jdk1.5上(服務端),使用spring2.5.6框架管理bean,而另一個執行在jdk1.4環境下(客戶端)。現

webservice客戶超時

使用axis2生成webserice客戶端時,在引用的jar包axis2-kernel下的org.apache.axis2.client.Options類中預設設定通訊超時時間為30s,jar包原始碼如下,可以看到預設時間為final常量:package org.apache

CXF動態客戶呼叫webservice例項

使用CXF實現WebService,並在客戶端實現動態呼叫編寫伺服器注意事項 注意 :不要指定 @SOAPBinding(style=Style.RPC, use=Use.LITERAL) 因為cxf 不支援:rpc、encoded,在動態客戶呼叫過程。 cxf w

CXF中wsdl2java命令生成webService客戶程式碼

1.wsdl2java工具的使用前準備,下載apache-cxf-2.7.2�工具� 一、環境配置         新建CXF_HOME      C:\ProgramFiles(my)\apache-cxf-2.7.2         在CLASSPATH    

CXF建立webservice客戶和服務

一、CXF的介紹 Apache CXF是一個開源的WebService框架,CXF大大簡化了Webservice的建立,同時它繼承了XFire的傳統,一樣可以和spring天然的進行無縫的整合。CXF框架是一種基於servlet技術的SOA應用開發框架,要正常運用基於CX

Webservice客戶動態調用服務功能方法

test 分享 exceptio client size 缺點 efi 末尾 bindings 一、發布WebService服務 方式一:在服務端生成wsdl文件,下方客戶端直接引用即可 優點:針對要發布的方法生成一個wsdl文件即可,無需多余配置。 缺點:每

webservice客戶調用

err index point tope wsdl exc sys xcod clas public static void main(String[] args) { try { String endpoint = "http://1.

學習 WebService 第四步:利用WSDL(URL)生成WebService客戶<初級>

SM documents eight 生成 web gen get JD OS 我用的是最簡單的方法,利用jdk的命令wsimport -keep -p 包路徑 -d 代碼存放位置 WSDL網址 藍色是命令,粉色是存放位置,橘色是URL C:\Program Files\

webservice客戶調用服務異常 —— 遠程主機強迫關閉了一個現有的連接

chain ati download .proto conn 驗證 使用 use real 最近遇到一個比較棘手的問題: 問題是這樣的,搭建了一個webservice的服務平臺,讓後提供給多個接口調用,有兩家接口調用了同樣的一個方法,但是第一家的接口從來沒有出現過問題,而另

采用WebService客戶調用WSDL/SOAP網絡報錯的解決辦法

客戶 運行 重置 情況 系統 net 發生 瀏覽器中 錯誤 WebService接口是網絡傳輸控制的重要途徑,在Windows系統下運行客戶端時,平時一直能正確運行,但某天可能突然會發生調用wsdl soap郵件標頭無法識別等莫名其妙的錯誤提示,出現這種情況一

webservice客戶生成方式

IE ide lib 自動 返回 client idea pro 選項 1.idea中File-new-Project 在彈出框中選擇java選項,選擇WebServices Client, 2.選擇Use library: 在本地中找到相關的lib包使用 (1)axi

WebService客戶(以命令方式創建)

查看 oca except user sage png host bin ESS 以命令的方式生成WebService客戶端: 創建一個Project項目,客戶端項目名稱WS_Client,在cmd界面進入JDK的bin目錄,輸入以下命令 完整格式: C:\Program