zoukankan      html  css  js  c++  java
  • Axis2 客户端调用 设置超时时间

    我用的是axis2-1.6.2版本。请看下面的客户端代码:

    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;

    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);
    }

    }

    如果上面设置不生效,有可能是你的版本旧了。还有一种方法可以试试:

    options.setProperty(HTTPConstants.SO_TIMEOUT, 300000);

    axis2底层调用的是httpclient,它默认的尝试连接时间是60s,建立连接后,等待接收数据的时间也是60s。上面的写法是把等待接收数据时间延长。

  • 相关阅读:
    U1
    std::vector的内存释放
    (转)浅谈PostgreSQL的索引
    PostgreSQL的generate_series函数应用
    linux 里的`反引号
    wireshark抓取本地回环数据包
    linux shell中 if else以及大于、小于、等于逻辑表达式介绍
    c++利用互斥锁实现读写锁
    c++互斥锁的实现
    大小端,"字节序"
  • 原文地址:https://www.cnblogs.com/dingmy/p/3712204.html
Copyright © 2011-2022 走看看