Timeout is not equal timeout

Last week I had to change a webservice-client in such a way as to be able to configure a timeout. The webservice is implemented with spring-webservices and uses the WebServiceTemplate class.I did not find a hint on how to configure a timeout in the documentation, but I found some comments on both classes, which handle the transport over http (HttpUrlConnectionMessageSender und CommonsHttpMessageSender). In my case it was CommonsHttpMessageSender (by default spring-webservices uses HttpUrlConnectionMessageSender).
CommonsHttpMessageSender has a property named readTimeout. I defined the desired value in my xml-configuration and tested the whole thing. At first glance everything worked fine – the client aborted with a exception if the server does not deliver in the desired period of time. During a further test I forgot to start the server where the webservice was deployed. What happend? The configured timeout did not make an impact.
At this point I will shorten the story. The http-client distinguishes between two different timeouts – http.connection.timeout and http.socket.timeout. http.connection.timeout is the timeout until a connection is established. And http.socket.timeout is the amount of time the client will wait for the server to deliver the data. The second timeout (http.socket.timeout) will show an impact only if the connection is already established. So if you do not want the client to block the current thread you should define both timeouts.

the resulting configuration could look like this:

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
<bean id="httpSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<property name="connectionTimeout" value="3000" />
<property name="readTimeout" value="5000" />
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="messageSender" ref="httpSender" />
  • Facebook
  • Delicious
  • Digg
  • StumbleUpon
  • Reddit
  • Blogger
  • LinkedIn
Eugen Melnichuk

4 Responses to Timeout is not equal timeout

  1. Michael says:

    Laut JavaDoc setzt man den Timeout in Millisekunden. Mit den gesetzten Timeouts (3 und 5 Miilisekunden) dürfte höchstens bei localhost-Zugriffen eine Verbindung möglich sein. Über ein Netzwerk aber bestimmt nicht.

  2. Vito Meuli says:

    Thanks a lot!
    Other posts about the same matter do not underline such important differences.

  3. Very helpful, especially the distinction between the two types of timeout. Thank you!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>