hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PercyChris @ Hotmail" <percych...@hotmail.com>
Subject RE: java.net.SocketTimeoutException: Read timed out after an IOException of type java.net.ConnectException Connection refused
Date Mon, 26 Jan 2009 19:30:56 GMT


-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: maandag 26 januari 2009 20:05
To: HttpClient User Discussion
Subject: Re: java.net.SocketTimeoutException: Read timed out after an
IOException of type java.net.ConnectException Connection refused

PercyChris @ Hotmail wrote:
> 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.
> 

Christian,

What for? Why creating a new instance of HttpClient? This does not make 
sense. Simply close all idle connections in the pool and continue using 
the same instance of HttpClient.

OK Using the same JAVA Object would be an option, but as I have to code
available anyway to construct an HTTPClient from a hostConfiguration object
I figured that simply invoking the method again with the new host
configuration object (which has been instantiated beforehand would do the
trick. The re-creation of the MultiThreadedHttpConnectionManager was only
implemented as a desperate action to circumvent the timeout.
I guessed that down below a TCP/IP connection which was corrupted was lying
around and was being reused causing my problem (but afterwards it seemed not
the case. At least it did not solve the problem)

Oleg

> 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;
> 
>  
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


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