Axis2 客戶端調用 設置超時時間

 

我用的是axis2-1.6.2版本。請看下面的客戶端代碼:apache

import org.apache.axis2.client.Options;數組

import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub;
import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub.OpenAndCheck;
import com.ctis.ta.service.impl.OpenAccountForUnitServiceStub.OpenAndCheckResponse;ide

public class Main {工具

    public static void main(String[] args) throws Exception {
        //OpenAccountForUnitServiceStub 是Axis2工具自動生成的類
        OpenAccountForUnitServiceStub stub = new OpenAccountForUnitServiceStub();
        OpenAndCheck openAndCheck = new OpenAndCheck();//openAndCheck 是服務端的方法
        openAndCheck.setAddress("");//設置服務端方法OpenAndCheck()的參數值

       Options options = stub._getServiceClient().getOptions();
        options.setTimeOutInMilliSeconds(3);//設置超時(單位是毫秒)
        stub._getServiceClient().setOptions(options);

        OpenAndCheckResponse response = stub.openAndCheck(openAndCheck);//開始調用服務端的方法openAndCheck
        String[] ret = response.get_return();//服務端返回一個數組
        System.out.println(ret.length);
    }spa

}get

 

若是上面設置不生效,有多是你的版本舊了。還有一種方法能夠試試:it

options.setProperty(HTTPConstants.SO_TIMEOUT, 300000);io

axis2底層調用的是httpclient,它默認的嘗試鏈接時間是60s,創建鏈接後,等待接收數據的時間也是60s。上面的寫法是把等待接收數據時間延長。class

相關文章
相關標籤/搜索