Hi All,
I have a strange problem with timeout handling in httpclient 3.1. For a client I am connecting to his backoffice at some url with basic authentication. Everything works fine, until I set the timeouts. If I don't set timeouts, the call will complete in 1000-2000ms. If I set the timeouts to 4000ms, the calls will ALWAYS take more than 4000ms to complete, most of the time even 8000+. I tested with different other urls of my own (with authentication, without, etc). If I use a url managed by myself on my own server, the timeout setting work fine. What could be causing this strange delay? I am running jdk 1.5.0 on Windows XP SP2. Here's the code I use. The urls and credentials in the code are from my own testserver (and working for outside world). public class TestCommunicator { public static void main(String[] args) throws Exception { String requestXmlAsString = "<xml><name>Some bogus xml for this test</name></xml>"; for (int i = 0; i<250; i++) { requestXmlAsString += "<xml><name>Some bogus xml for this test</name></xml>"; } System.out.println("REQUEST="); System.out.println(requestXmlAsString); long processStartTime = System.currentTimeMillis(); HttpClient httpClient = new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); Credentials credentials = new UsernamePasswordCredentials("valentijn", "testvalentijn"); httpClient.getState().setCredentials(new AuthScope("62.212.90.124" , 443 , AuthScope.ANY_REALM), credentials); PostMethod pm = new PostMethod("https://62.212.90.124/valentijn/"); pm.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); pm.addRequestHeader("Content-Type", "application/x-sap.busdoc"); pm.setDoAuthentication(true); pm.setRequestEntity(new StringRequestEntity(requestXmlAsString)); Integer connectionTimeout = 4000; pm.getParams().setParameter("http.socket.timeout", connectionTimeout); pm.getParams().setParameter("http.connection.timeout", connectionTimeout); httpClient.getParams().setParameter("http.socket.timeout", connectionTimeout); httpClient.getParams().setParameter("http.connection.timeout", connectionTimeout); try { // Send and parse int httpResponseCode = httpClient.executeMethod(pm); if(httpResponseCode == 200){ // Get responsebody as XML System.out.println("RESPONSE="); System.out.println(pm.getResponseBodyAsString()); long processEndTime = System.currentTimeMillis(); System.out.println (">>> This action took : " + (processEndTime-processStartTime) + " ms."); } else{ // The responsedata may be an XML form. If so, create a nice, readable XML file. Otherwise, // just return the responsedata as a String object. String responseBody = ""; System.out.println("RESPONSE="); System.out.println(pm.getResponseBodyAsString()); long processEndTime = System.currentTimeMillis(); System.out.println (">>> This action took : " + (processEndTime-processStartTime) + " ms."); throw new Exception("Wrong responsecode returned."); } } catch (HttpException e) { e.printStackTrace(); long processEndTime = System.currentTimeMillis(); System.out.println (">>> This action took : " + (processEndTime-processStartTime) + " ms."); } catch (IOException e) { e.printStackTrace(); long processEndTime = System.currentTimeMillis(); System.out.println (">>> This action took : " + (processEndTime-processStartTime) + " ms."); } } } Met vriendelijke groet / With kind regards, ir Valentijn Scholten Applicatie Architect ISAAC Software Solutions e-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> url: http://www.isaac.nl <http://www.isaac.nl/> tel: +31 (0)40-2155357 fax: +31 (0)40-2908980