hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PercyChris @ Hotmail" <percych...@hotmail.com>
Subject java.net.SocketTimeoutException: Read timed out after an IOException of type java.net.ConnectException Connection refused
Date Sun, 25 Jan 2009 14:38:45 GMT
Dear,

 

I am using the HTTP Client 3.1 with JAVA JDK 1.6

I am connecting to an Apache (redundant) server using HTTPS.

All works fine until I kill the Apache server.

The program is made to switch to the second server when it detects a problem
with the first.

When this happens I receive an IOException of type java.net.ConnectException
Connection refused (expected).

On this I create a new HttpClient with the new host parameters.

The first (few, 2 to 3) POST to the new host succeeds, but then I always get

java.net.SocketTimeoutException: Read timed out. (The POST has then been
executing for 15 seconds, the server is expected to respond within 90
seconds)

Whatever I do, even shutting down the MultiThreadedHttpConnectionManager and
creating a new one.

The problem only occurs when I have to switch hosts (create a new
HttpClient)

 

If I cannot find a solution then the only thing that rests is to kill the
whole VM and restart the application (that works until I have to switch
hosts again)

 

I add the code of the creation of the HTTP client and the execution of the
Post method.

I deleted all parts I think are irrelevant (such as logging etc)

 

Any suggestion on how to proceed to find the cause or what to verify or
change would be greatly appreciated.

 

Thanks in advance for your information and concern to help me out here

 

Percy Christian

 

 

// Creation of an HTTPClient
                               HttpClient httpClient = new
HttpClient(httpConnectionManager);
                               HttpConnectionParams httpConnectionParams =
httpConnectionManager.getParams();
            int connectionTimeout =
currentHostConfiguration.getConnectionTimeout();

            if (connectionTimeout != 0)

            {

              httpConnectionParams.setConnectionTimeout(connectionTimeout *
1000);

            }

httpConnectionParams.setSoTimeout(getSocketTimeout()*1000); // IS actually
180*1000

 
httpClient.getParams().setAuthenticationPreemptive(true);
 
httpState.setCredentials(currentHostConfiguration.getAuthScope(),
currentHostConfiguration.getUsernamePasswordCredentials());

// Post method
                               PostMethod post = new
PostMethod(currentHostConfiguration.getURL());
                               post.setRequestEntity(requestEntity);
                               post.setRequestHeader("Content-type",
"text/xml; charset=ISO-8859-1");
                               post.setDoAuthentication(true);
                               try
                               {
                                               int result =
client.executeMethod(post);
                                               InputStream input =
post.getResponseBodyAsStream();
                                               if (input != null)
                                               {
                                                       response =
readStream(input);
                                               }
                                               else
                                               {
                                                 // This is last resort.
                                                 response =
post.getResponseBody();
                                               }
                               }
                               catch (HttpException e)
                               {

                                               HttpCommunicationException
wrapper = new HttpCommunicationException(message, e);
                                               throw wrapper;
                               }
                               catch (IOException e)
                               {
                                               HttpCommunicationException
wrapper = new HttpCommunicationException(message, e);
 
serverConnectionLost(wrapper);
                                               throw wrapper;
                               }
                               finally
                               {
                                               post.releaseConnection();
                               }
                               return response;

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message