Web Service Read timed out

Test first is not a silver bullet; there are still things you may not see until much later. I ran into a read time out recently that was only manifesting on a pre-production server. The stack trace indicated what was going on but the site’s behaviour was not what I would have expected.

2008-04-15 09:25:36,387 ERROR [com.foo.bar.service.impl.ServiceImpl] - 
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.SocketTimeoutException: Read timed out
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at org.apache.axis.transport.http.HTTPSender.readHeadersFromSocket(HTTPSender.java:583

Anyway, after a bit of head scratching, it ended up being quite straightforward to recreate locally by simply overriding the JaxRpcPortProxyFactoryBean and setting the timeout to something unreasonably small.

import javax.xml.rpc.Stub; 
import org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean; 

public class ServiceJaxRpcFactoryBean extends JaxRpcPortProxyFactoryBean { 
  private static final String TIMEOUT_PROPERTY_KEY = "axis.connection.timeout"; 
  protected void preparePortStub(Stub stub) { 
    super.preparePortStub(stub); 
    stub._setProperty(TIMEOUT_PROPERTY_KEY, new Integer(100)); 
  } 
}
comments powered by Disqus