axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pppp ssss <iis...@yahoo.com>
Subject Re: Problem w/ REUSE_HTTP_CLIENT and AUTO_RELEASE_CONNECTION
Date Sun, 14 Sep 2008 20:18:01 GMT
Hello all,

After 1 day away of this problem I does a workaround, which is working for me and wanted to
share it in case someone find it usefull.
First I found, that there is really a problem with AUTO_RELEASE_CONNECTION - connection is
released on HTTP code level and all pending socket data is consumed. Later on higher code
level this socket data is requested, but it is too late and Exception is thrown. I don't know
how such a big problem may exists in the last AXIS2 releases. (tested with 1.3, 1.4, 1.4.1)

As my client is using HTTP as transport protocol I isolated the problem on HTTP code level.
I created my own connection manager, which extends MultiThreadedHttpConnectionManager and
plugs it into a custom HttpClient, which my client is using. 
I overwrite getConnectionWithTimeout(..) method and implemented a register for all returned
HttpConnections. After this I implemented a simple RPC proxy, which wraps AXIS2 blocking and
non blocking calls. At the end it was easy to release used HTTP connection after AXIS2 call
is done.

This way I'm able to implement AXIS2 client, using shared HttpClient, with HTTP 1.1 and 2
connections in pool - always in ESTABLISHED state. This is far from a perfect solution, but
I'll  live with it untill AXIS2 guys provide a real solution.

Some code:

MyConnectionManager connectionManager = new MyConnectionManager();
....
HttpClient httpClient = new HttpClient(connectionManager);
....
ConfigurationContext configcontext = ConfigurationContextFactory.createDefaultConfigurationContext();

configcontext.setThreadPool(new ThreadPool(1, 3));
configcontext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
configcontext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
RPCServiceClient sender = new RPCServiceClient(configcontext, null);
......
sender.invokeBlocking(opName, args);
connectionManager.releaseConnections();

======================================

public class MyConnectionManager extends MultiThreadedHttpConnectionManager {
   ....

   public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long
to) 
             throws ConnectionPoolTimeoutException {
       myConnection = super.getConnectionWithTimeout(hostConfiguration, to); 
       // TODO: put my connection in connections-in-use register - depends on you

       return(myConnection);
     }

    public void releaseConnections() {
       // TODO: release not-in-use connections - depends on you
    }
}

Best Regards,
Paco


----- Original Message ----
From: pppp ssss <iisdml@yahoo.com>
To: axis-user@ws.apache.org
Sent: Saturday, September 13, 2008 7:35:02 PM
Subject: Problem w/ REUSE_HTTP_CLIENT and AUTO_RELEASE_CONNECTION


Hello all,

After a lot of mailing lists/doc/source reading and many tests I can't figure out how to implement
Axis2 client, which uses REUSE_HTTP_CLIENT and AUTO_RELEASE_CONNECTION.
I'm always getting following Exception "org.apache.axis2.AxisFault: Attempted read on closed
stream."

Here is my simple test case and Exception below. I'm building with Axis2 1.4 and Axis2 1.4.1
- no difference.

==========================================================
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
connectionManagerParams.setDefaultMaxConnectionsPerHost(2);
connectionManagerParams.setTcpNoDelay(true);
connectionManagerParams.setStaleCheckingEnabled(true);
connectionManagerParams.setLinger(0);
connectionManager.setParams(connectionManagerParams);
MyHttpClient httpClient = new MyHttpClient(connectionManager);

ConfigurationContext configcontext = 
ConfigurationContextFactory.createDefaultConfigurationContext(); 
configcontext.setThreadPool(new ThreadPool(1, 3));
configcontext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,
Boolean.TRUE);
configcontext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT,
httpClient);

RPCServiceClient sender = null;
sender = new RPCServiceClient(configcontext, null);

Options options = sender.getOptions();
options.setTo(targetEPR);
options.setTimeOutInMilliSeconds(TIMEOUT);
options.setProperty(HTTPConstants.CHUNKED, Boolean.TRUE);
options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT);
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);

options.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, Boolean.TRUE);

QName opName = new QName("http://um.axis2.es.iisd.com", "login");
Object[] args = new Object[] { "*", "*" };
sender.invokeNonBlocking(opName, args, callback);
//OMElement element = sender.invokeBlocking(opName, args);
==========================================================

I'm trying to execute blocking and non blocking requests - the same Exception occures.

Exception:

org.apache.axis2.AxisFault: Attempted read on closed stream.
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:61)
at org..apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils..java:164)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:441)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent..ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang..Thread.run(Unknown Source)
Caused by: java.io.IOException: Attempted read on closed stream.
at org.apache.commons.httpclient.AutoCloseInputStream.isReadAllowed(AutoCloseInputStream.java:183)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:107)
at java.io.FilterInputStream.read(Unknown Source)
at java.io.PushbackInputStream.read(Unknown Source)
at org.apache.axis2.builder.BuilderUtil.getCharSetEncoding(BuilderUtil.java:281)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder..java:48)
.... 9 more

Thank for your help in advance
Paco 


      
Mime
View raw message