Apache Axis2 Client Service Timeout

By | September 25, 2021

I used the Apache Axis2 Client service to send a request to a service provider. However, the processes take too long, sometime up to 5 minutes at the service provider side. As result, my request is always timeout after 60 seconds. My application is written by Spring Boot and maven configuration to generate Java code from my WSDL.


<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
   <version>${axis2.version}</version>
   <executions>
      <execution>
         <id>myservice</id>
         <goals>
            <goal>wsdl2code</goal>
         </goals>
         <configuration>
            <outputDirectory>src/generated-sources/myservice</outputDirectory>
            <wsdlFile>src/main/resources/MyWSDL.wsdl</wsdlFile>
            <packageName>com.example.services</packageName>
            <unpackClasses>true</unpackClasses>
            <unwrap>true</unwrap>
         </configuration>
      </execution>
   </executions>
</plugin>


First, I worked around with Nginx configuration

location / {
        proxy_read_timeout 300000s;
        proxy_connect_timeout 300000s;
        proxy_send_timeout 300000s;
        send_timeout 300000s;
        keepalive_timeout 300000s;
}

And increase the connection timeout for the Apache Axis2 Service Client however it doesn’t help much.

ServiceClient sc = webserviceStub._getServiceClient();
webserviceStub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);

I do double-check from Apache Axis2 HTTP Transport: Two timeout instances exist in the transport level, Socket timeout and Connection timeout. I recognized that I missed Socket timeout configuration. Fix and testing with following configuration it worked well with requests more than 60 seconds.

@Configuration
public class WebServiceStubConfig {
  
    @Bean
    WebserviceStub getWebserviceStub() throws AxisFault {
        WebserviceStub webserviceStub = new WebserviceStub();
        ServiceClient sc = webserviceStub._getServiceClient();
        Options options = sc.getOptions();
        options.setProperty(HTTPConstants.SO_TIMEOUT, 300000);
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 300000);
        sc.setOptions(options);
        webserviceStub._setServiceClient(sc);
        return webserviceStub;
    }

}

If you have a WSDL, you can test with any Soap application to see how long does a request take? In my case, I use the Soap UI application to address the timeout problem by setting a Socket Timeout property as figure below in SoapUI references. My web service provider has one of services that process more than 60 seconds, up to five minus to complete in worst case.

Thank you for reading my note.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.