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

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

  1. org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection  
  2.     at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)  
  3.     at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)  
  4.     at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)  
  5.     at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)  
  6.     at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)  
  7.     at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)  
  8.     at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)  
  9.     at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)  
  10.     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)  
  11.     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)  
  12.     at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)  
  13.     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)  
  14.     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)  
  15.     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)  
  16.     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)  
  17.     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)  
  18.     at com.res.rc.client.RPCClient.callService(RPCClient.java:282)  
  19.     at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)  
  20.     at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)  
  21.     at com.res.framework.handler.OnlineHandler.handleRequest(Unknown Source)  
  22.     at com.res.framework.servlet.GenericFrameworkServlet.doService(Unknown Source)  
  23.     at com.res.framework.servlet.GenericFrameworkServlet.doPost(Unknown Source)  
  24.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)  
  25.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  
  26.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
  27.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  28.     at com.res.portal.init.SetCharacterEncodingFilter.doFilter(Unknown Source)  
  29.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  
  30.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  31.     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)  
  32.     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)  
  33.     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)  
  34.     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)  
  35.     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  
  36.     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)  
  37.     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)  
  38.     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)  
  39.     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)  
  40.     at java.lang.Thread.run(Thread.java:619)  
  41. org.apache.axis2.AxisFault: Timeout waiting for connection  
  42.     at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)  
  43.     at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:203)  
  44.     at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)  
  45.     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)  
  46.     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)  
  47.     at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)  
  48.     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)  
  49.     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)  
  50.     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)  
  51.     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)  
  52.     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)  
  53.     at com.res.rc.client.RPCClient.callService(RPCClient.java:282)  
  54.     at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)  
  55.     at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)  
  56.     at com.res.framework.handler.OnlineHandler.handleRequest(Unknown Source)  
  57.     at com.res.framework.servlet.GenericFrameworkServlet.doService(Unknown Source)  
  58.     at com.res.framework.servlet.GenericFrameworkServlet.doPost(Unknown Source)  
  59.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)  
  60.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  
  61.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
  62.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  63.     at com.res.portal.init.SetCharacterEncodingFilter.doFilter(Unknown Source)  
  64.     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  
  65.     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  66.     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)  
  67.     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)  
  68.     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)  
  69.     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)  
  70.     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  
  71.     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)  
  72.     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)  
  73.     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)  
  74.     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)  
  75.     at java.lang.Thread.run(Thread.java:619)  

解决办法:

  1. try  
  2. {  
  3.     serviceClient = new RPCServiceClient ();  
  4.     Options options = serviceClient.getOptions();  
  5.     //  指定调用WebService的URL  
  6.     EndpointReference targetEPR = new EndpointReference(wsURL);  
  7.     options.setTo(targetEPR);  
  8.     options.setManageSession(true);   
  9.     options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);   
  10.     //指定某调用方法的参数值  
  11.      Object[] opAddEntryArgs = inParams;  
  12.      Class[] classes = outParamClass;  
  13.     //  指定要调用的getGreeting方法及WSDL文件的命名空间  
  14.       QName opAddEntry = new QName(nameSpace, methodName);  
  15.      Object[] result=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes);  
  16.      serviceClient.cleanupTransport();  
  17.  }  
  18.  catch (AxisFault e)  
  19.  {  
  20.     e.printStackTrace();  
  21.  }  
  22.  catch (Exception e)   
  23.  {  
  24.     e.printStackTrace();  
  25.  }  


上述代码中的

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

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

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


原文网址:http://blog.csdn.net/liufeng520/article/details/8464211


你可能感兴趣的:(J2EE开发框架,WebService,axis2)