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" />



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