多次使用axis2调用webservice后,报连接超时错误

使用Axis2d的RPCServiceClient调用webservice,连续调用几次web服务后,后台报错,如下所示:

org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
	at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)
	at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
	at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
	at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)
	at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
	at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
	at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
	at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
	at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)
	at com.res.rc.client.RPCClient.callService(RPCClient.java:282)
	at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)
	at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)
	at com.res.framework.handler.OnlineHandler.handleRequest(Unknown Source)
	at com.res.framework.servlet.GenericFrameworkServlet.doService(Unknown Source)
	at com.res.framework.servlet.GenericFrameworkServlet.doPost(Unknown Source)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.res.portal.init.SetCharacterEncodingFilter.doFilter(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)
org.apache.axis2.AxisFault: Timeout waiting for connection
	at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
	at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:203)
	at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
	at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
	at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
	at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
	at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
	at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)
	at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)
	at com.res.rc.client.RPCClient.callService(RPCClient.java:282)
	at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)
	at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)
	at com.res.framework.handler.OnlineHandler.handleRequest(Unknown Source)
	at com.res.framework.servlet.GenericFrameworkServlet.doService(Unknown Source)
	at com.res.framework.servlet.GenericFrameworkServlet.doPost(Unknown Source)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.res.portal.init.SetCharacterEncodingFilter.doFilter(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

解决办法:

try
{
    serviceClient = new RPCServiceClient ();
    Options options = serviceClient.getOptions();
    //  指定调用WebService的URL
    EndpointReference targetEPR = new EndpointReference(wsURL);
    options.setTo(targetEPR);
    options.setManageSession(true); 
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true); 
    //指定某调用方法的参数值
     Object[] opAddEntryArgs = inParams;
     Class[] classes = outParamClass;
    //  指定要调用的getGreeting方法及WSDL文件的命名空间
      QName opAddEntry = new QName(nameSpace, methodName);
     Object[] result=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes);
     serviceClient.cleanupTransport();
 }
 catch (AxisFault e)
 {
    e.printStackTrace();
 }
 catch (Exception e) 
 {
    e.printStackTrace();
 }


上述代码中的

options.setManageSession(true); 
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true); 
serviceClient.cleanupTransport();

可以解决多次调用webservice后的连接超时异常
该错误参照apache官网:

https://issues.apache.org/jira/browse/AXIS2-4797 

转载:http://www.itkeyword.com/doc/4295590002354076696/class-apache-object

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值