Axis2如何设置连接超时时间
客户端调用webservice服务端的时候,我想设置一下连接超时的时间,客户端代码如下,测了几次,要80多秒才抛连接超时,想自己设一个,15秒左右的,高手指点下怎么弄RP...
客户端调用webservice服务端的时候,我想设置一下连接超时的时间,客户端代码如下,测了几次,要80多秒才抛连接超时,想自己设一个,15秒左右的,高手指点下怎么弄
RPCServiceClient serviceClient = null;
Map<String, String> map = null;
long begin = 0;
try {
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 指定调用webservice的url
EndpointReference targetEPR = new EndpointReference(
"-------------url---------------------------------");
options.setTimeOutInMilliSeconds((long)30000);
options.setTo(targetEPR);
// 指定方法的参数值
Object[] opAddEntryArgs = new Object[] { "-3e7a6595:134abc78829:-7fbd", 222222, "555555" };
// 指定方法的返回值的数据类型的class对象
Class[] classes = new Class[] { String.class };
// 指定要调用的方法及wsdl文件的命名空间,对应xml中的targetnamespace值
QName opAddEntry = new QName("----------------------/xsd", "getMessage");
// 调用方法(当有返回值时)
begin = System.currentTimeMillis();
System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0].toString());
} catch (AxisFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
long end = System.currentTimeMillis();
System.out.println("-----------------"+(end-begin)+"------------------");
}
options.setTimeOutInMilliSeconds((long)30000);
这句话根本不起作用,急啊!!! 展开
RPCServiceClient serviceClient = null;
Map<String, String> map = null;
long begin = 0;
try {
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 指定调用webservice的url
EndpointReference targetEPR = new EndpointReference(
"-------------url---------------------------------");
options.setTimeOutInMilliSeconds((long)30000);
options.setTo(targetEPR);
// 指定方法的参数值
Object[] opAddEntryArgs = new Object[] { "-3e7a6595:134abc78829:-7fbd", 222222, "555555" };
// 指定方法的返回值的数据类型的class对象
Class[] classes = new Class[] { String.class };
// 指定要调用的方法及wsdl文件的命名空间,对应xml中的targetnamespace值
QName opAddEntry = new QName("----------------------/xsd", "getMessage");
// 调用方法(当有返回值时)
begin = System.currentTimeMillis();
System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0].toString());
} catch (AxisFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}finally {
long end = System.currentTimeMillis();
System.out.println("-----------------"+(end-begin)+"------------------");
}
options.setTimeOutInMilliSeconds((long)30000);
这句话根本不起作用,急啊!!! 展开
2个回答
展开全部
应该可以的,setTimeOutInMilliSeconds是设毫秒的喔,你尝试一下再改短一点。setTimeOutInMilliSeconds(100L)。
org.apache.commons.httpclient.ConnectTimeoutException: The host did not accept the connection within timeout of 100 ms
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:155)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
org.apache.commons.httpclient.ConnectTimeoutException: The host did not accept the connection within timeout of 100 ms
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:155)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
展开全部
MultiThreadedHttpConnectionManager conmgr = new MultiThreadedHttpConnectionManager();
conmgr.getParams().setSoTimeout( 10000 ); //10秒
HttpClient httpclient = new HttpClient(conmgr);
....
options.setProperty( HTTPConstants.CACHED_HTTP_CLIENT, httpclient );
......
serviceClient.setOptions(options);
conmgr.getParams().setSoTimeout( 10000 ); //10秒
HttpClient httpclient = new HttpClient(conmgr);
....
options.setProperty( HTTPConstants.CACHED_HTTP_CLIENT, httpclient );
......
serviceClient.setOptions(options);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询