It looks like Spring's WebServiceTemplate is ignoring setting for connection timeout. That, or I am misunderstanding connection timeout.
Here is my configuration:
@Bean
public SoapTemplate soapTemplate(Jaxb2Marshaller marshaller, WebServiceMessageSender webServiceMessageSender ) {
SoapTemplate template = new SoapTemplate();
template.setDefaultUri("some_url");
template.setMarshaller(marshaller);
template.setUnmarshaller(marshaller);
template.setMessageSender(webServiceMessageSender);
return template;
}
@Bean
public WebServiceMessageSender webServiceMessageSender() {
HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
sender.setReadTimeout(5*1000);
sender.setConnectionTimeout(5*1000);
return sender;
}
Soap template extends WebServiceGateway and has some specific logging, custom exception features.
When I start target application which should receive SOAP messages generated by WebServiceTemplate, read timeout works as intended. If the server does not respond within specified time, an exception is thrown.
My understanding was that connection timeout should happen if the TCP 3-Way Handshake doesn't happen within specified time. This is not the case however, as timeout always happens after ~ 2 second, regardless of my configuration.
Is this a valid test, or connection timeout should be tested with congested server that is online but cannot accept new connections ? Which timeout is my client experiencing then and can it be controlled ?