Search code examples
javaeclipsehttpserviceapache-axis

How could I change "http.connection-manager.timeout"?


Basically, I am using Apache Axis2. Working with it, I can change any timeout I want, but no the title's one. I'm working with Java & Eclipse.

I have a project where we are testing some web services. On it, I'm implementing a test using ServiceClient and Options, changing the properties of the timeout that it has.

However, I could change 2 of 3 timeouts parameters that are the following: - http.connection-manager.timeout (can't change it). - http.connection.timeout (can be changed). - http.socket.timeout (can be changed).

I've tried so many ways trying to change the first one, but I've not found how to do it.

As you can see below, the "600000" value are the fields which I could change, and the "30000" is the one which not (I think 30000 is the value by default).

I'm going to show you the part of the code where I'm working on it and the console output.


[CODE]

int timeoutMS = 600000;

ServiceClient serviceClient = stub._getServiceClient();

Options options = serviceClient.getOptions();

options.setTimeOutInMilliSeconds(timeoutMS); options.setProperty(HTTPConstants.SO_TIMEOUT, timeoutMS); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeoutMS);

[CONSOLE OUTPUT]

[DEBUG 2019/01/10 16:15:15,236] Set parameter http.connection-manager.timeout = 30000

[DEBUG 2019/01/10 16:15:15,237] Set parameter http.connection.timeout = 600000

[DEBUG 2019/01/10 16:15:15,237] Set parameter http.socket.timeout = 600000


As you can see, my expected results where the three parameters with a "600000" value, but the first one keeps the value by default.

Thanks in advance!


Solution

  • I stumbled upon this same issue at work. After several hours of researching, we finally found an approximation to the solution. Here is what we've got:

    MultiThreadedHttpConnectionManager connectionManager;
    void configureCachedHttpClient() {
            connectionManager = new MultiThreadedHttpConnectionManager();
            HttpConnectionManagerParams params = connectionManager.getParams();
            params.setConnectionTimeout(timeout); // set connection timeout (how long it takes to connect to remote host)
            params.setSoTimeout(timeout); // set socket timeout (how long it takes to retrieve data from remote host)
            params.setDefaultMaxConnectionsPerHost(maxTotalConnections);
            params.setMaxTotalConnections(maxTotalConnections);
    
            HttpClient httpClient = null;
            try {
                httpClient = new HttpClient(connectionManager);
                HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
                connectionManagerParams.setParameter("http.connection-manager.timeout", timeout); // set timeout on how long we'll wait for a connection from the pool
    
                context.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connectionManager);
                context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
                context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
                // context.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true);
            } catch (Exception e) {
                // Exception e
                httpClient = null;
                e.printStackTrace();
            } finally {
                httpClient = null;
            }
        }
    

    As you state in question, the lines in above's snippet are required to change 'http.connection-manager.timeout' property. It is mandatory to instance 'org.apache.commons.httpclient.MultiThreadedHttpConnectionManager', as well as initialize an 'org.apache.commons.httpclient.HttpClient' object, to further configure it. Once it is set as we need, we have to set the last 3 properties as is shown below.

    When it has been configured and set, Axis will use that httpclient instance we set at the end; therefore, every new connection/communication to a web service will be preconfigured as stated.

    Hope this can help you; I'm sorry if it's not complete enough. Will complete this answer if needed.

    [EDIT]

    As you show in question, here is an extract of our log:

    ...
    [DEBUG 2019/01/22 17:42:30.719] Set parameter http.connection.timeout = 120000
    [DEBUG 2019/01/22 17:42:30.719] Set parameter http.socket.timeout = 120000
    [DEBUG 2019/01/22 17:42:30.719] Set parameter http.connection-manager.max-per-host = {HostConfiguration[]=2}
    [DEBUG 2019/01/22 17:42:30.719] Set parameter http.connection-manager.max-total = 2
    [DEBUG 2019/01/22 17:42:31.597] Set parameter http.connection-manager.timeout = 120000
    ...