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。上面的写法是把等待接收数据时间延长。

时间: 2024-07-31 22:23:24

Axis2 客户端调用 设置超时时间的相关文章

socket为send和recv设置超时时间

linux和windows下用setsockopt设置SO_SNDTIMEO,SO_RCVTIMEO的参数的一点区别 UDP的socket在某些情况:如对方关闭时,本地可能sendto不出去数据,然后recvfrom就会被阻塞,这时就需要设置 这两个参数的值提高程序质量. linux: struct timeval timeout={3,0};//3s    int ret=setsockopt(sock_fd,SOL_SOCKET,SO_SNDTIMEO,(const char*)&timeo

java测试网络连接是否成功并设置超时时间

/** * 获取RMI接口状态 * * @return "0":服务正常,"1": 连接报错,"2":连接超时 */ @Override public String getRMIJkzt() { final ExecutorService es = Executors.newFixedThreadPool(1); Callable<String> callable = new Callable<String>() {//使

设置超时时间(项目案例仅供参考)

#设置超时时间爬取网页速度相对要快些#encoding:utf8from lxml import etree#xpathimport re#正则import time#时间import requests#传值from selenium import webdriver#通用阅览器from selenium.webdriver.support.ui import WebDriverWait#引用超时模块import random#自定义模块url = '(网址)'driver = webdrive

C# UdpClient 设置超时时间

/********************************************************************** * C# UdpClient 设置超时时间 * 说明: * 网络通信中设置超时时间是常有的时,记录UDP获取.发送超时设置方法. * * 2016-12-8 深圳 南山平山村 曾剑锋 *********************************************************************/ 一.参考文档: 1. Can

设置超时时间

// 设置超时时间 [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"]; manager.requestSerializer.timeoutInterval = 10.f; [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"]; http://www.itjhwd.com/ios-xuexzlzl/

apache httpclient4 设置超时时间

旧的方法(已被禁用) CloseableHttpClient httpclient = HttpClients.createDefault(); httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000); httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,5000); 新的方法 HttpPost httpp

如何为session设置超时时间?

要为session设置超时时间,首先要清楚怎么样算是超时, 超时时间是session自上一次活跃时间到本次开始活跃时间之间的间隔时间大于设置的session超时时间. 为session设置超时时间常用的方法有三种: 第一种方法: HttpSession session = request.getSession(true); session.setAttribute("user", user); session.setMaxInactiveInterval(30); 注意:单位是秒,设置

给file_get_contents函数设置超时时间

$opts = array( 'http'=>array( 'method'=>"GET", 'timeout'=>60, ) ); $context = stream_context_create($opts); $html =file_get_contents('http://www.example.com', false, $context); 这样,file_get_contents获取数据时,超出60秒将会自动退出. 还可以利用file_get_conten

Mybatis设置超时时间

Mybatis设置超时时间 mybatis如果不指定,默认超时时间是不做限制的,默认值为0.mybatis sql配置超时时间有两种方法: 1.全局配置 在mybatis配置文件的settings节点中,增加如下配置<settings>  <setting name="defaultStatementTimeout" value="25"/>  </settings> 以秒为单位的全局sql超时时间设置,当超出了设置的超时时间时,