5

I am using Axis2 in version:

Implementation-Version: 1.7.0-SNAPSHOT
Implementation-Vendor-Id: org.apache.axis2
Implementation-Vendor: The Apache Software Foundation
Jenkins-Build-Number: 1847

I want to set the timeout of the ServiceClient to 2000 milliseconds, this is our code:

Options options = new Options();
options.setTo(new EndpointReference(getUserServiceEndPoint()));
options.setProperty(Constants.Configuration.ENABLE_REST,
        Constants.VALUE_TRUE);
// setting timeout to 2 second should be sufficient, if the server is
// not available within the 3 second interval you got a problem anyway
options.setTimeOutInMilliSeconds(2000);

ServiceClient sender = new ServiceClient();
sender.engageModule(new QName(Constants.MODULE_ADDRESSING)
        .getLocalPart());
sender.setOptions(options);
OMElement getSessionResult = sender
        .sendReceive(getPayloadMethodGetSession());

However I still see in the logs:

org.apache.axis2.AxisFault: The host did not accept the connection within timeout of 60000 ms

And it really takes also 60 seconds. So the error message is not just wrong, it seems like the timeout option is just ignored and it always uses the default one.

Anybody had a similar issue ?

Thanks
Sebastian

seba.wagner
  • 3,800
  • 4
  • 28
  • 52

2 Answers2

5

I was able to resolve the issue (although it looks somehow duplicated to me)

int timeOutInMilliSeconds = 2000;
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
options.setProperty(HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeOutInMilliSeconds);

Sebastian

seba.wagner
  • 3,800
  • 4
  • 28
  • 52
  • 2
    It looks duplicated but the two timeouts have an important difference. The SO_TIMEOUT is the timeout for when trying to establish the connection to the server. CONNECTION_TIMEOUT is how long the socket will wait to receive the response after the request is sent. – Nick Roth Nov 23 '12 at 04:03
  • 2
    but what is options.setTimeOutInMilliSeconds(timeOutInMilliSeconds); good for? It seems to have no effect at all. – seba.wagner Nov 23 '12 at 04:08
  • I wish I could tell you. The javadoc on the Options class doesn't provide much info. I would have figured it to set both values using one method. My google-fu doesn't seem to readily get an answer either. – Nick Roth Nov 23 '12 at 04:23
  • @NickRoth I believe that you got the definition of an SO_TIMEOUT and a CONNECTION_TIMEOUT mixed up. The inverse of what you said is correct. – Mouhammed Soueidane Jun 26 '15 at 11:16
  • 1
    no effect of options.setTimeOutInMilliSeconds and options.setProperty HTTPConstants.CONNECTION_TIMEOUT .. – Santosh Jun 26 '16 at 13:28
  • its 2022 above solution still have no effect – aswzen Sep 27 '22 at 02:36
1

Per API doc of Axis2 1.6.3, it is either the two properties or the timeOutInMillis like :

Options options = new Options();
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));

OR

options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);

SOURCE: http://axis.apache.org/axis2/java/core/docs/http-transport.html

Majid Abarghooei
  • 663
  • 7
  • 21
  • I am not sure if the java classes are implemented as a wrapper on the c code, but in options.c the setTimeoutInMilliseconds is only modifying the connection timeout: axis2_options_set_property(options, env, AXIS2_HTTP_CONNECTION_TIMEOUT, property); – Marco Kinski Mar 30 '17 at 09:46
  • On the usage side the setTimeoutInMilliseconds vs SO_TIMEOUT only makes a difference when the curl backend gets used. – Marco Kinski Mar 30 '17 at 09:55