On Fri, 2005-11-04 at 20:10 +0000, Rudy Rusli wrote:
> Oleg,
> 
> I think there are two things that confuse me right now:
> 1. When I invoked SocketTimeoutException, I checked the connection with 
> ProcessExplorer.
> The connection is still there. It is gone after several IOExceptions are 
> thrown, but not immediately.

I believe SocketTimeoutException does not leave the socket in an
inconsistent state. The socket should still be perfectly usable

> 2. Many times after SocketTimeoutException is thrown, the reader.close() is 
> successfully executed without the warning: "Could not close 
> BufferedReader..." So the occurences of this warning seem to be random.
> 

Most likely in the latter case the connection was closed on the server
side

Hope this helps

Oleg

> Could you please advise?
> 
> Thanks for the ongoing help.
> 
> -Rudy-
> 
> ------------------------------------------------------------------------------------------------------------
> >From: Oleg Kalnichevski <[EMAIL PROTECTED]>
> >To: Rudy Rusli <[EMAIL PROTECTED]>
> >Subject: Re: Problem closing resources using Apache HttpClient.
> >Date: Fri, 4 Nov 2005 09:45:06 +0100
> >
> >Rudy,
> >
> >Because the InputStream#close() is called in InputStreamReader#close().
> >
> ------------------------------------------------------------------------------------------------------------
> >On Thu, Nov 03, 2005 at 11:27:01PM +0000, Rudy Rusli wrote:
> > > Oleg,
> > >
> > > Thanks for your email.
> > >
> > > So closing BufferedReader and InputStream will certainly fail if an I/O
> > > Exception has been thrown? Why do I only the warning message when I 
> >close
> > > the BufferedReader and not the InputStream then?
> ------------------------------------------------------------------------------------------------------------
> > > >From: Oleg Kalnichevski <[EMAIL PROTECTED]>
> > > >Reply-To: "HttpClient User Discussion" 
> ><[email protected]>
> > > >To: HttpClient User Discussion <[email protected]>
> > > >Subject: Re: Problem closing resources using Apache HttpClient.
> > > >Date: Thu, 03 Nov 2005 22:24:41 +0100
> > > >Rudy,
> > > >There is absolutely no reason to close the input stream if an I/O
> > > >exception has been thrown, as the underlying connection has already 
> >been
> > > >closed by HttpClient
> --------------------------------------------------------------------------------------------------------------
> > > >On Thu, 2005-11-03 at 20:57 +0000, Rudy Rusli wrote:
> > > >> I'm using Apache HTTPClient to connect to a data source.
> > > >>
> > > >> I set the connection timeout and the socket timeout in the 
> >constructor
> > > >of
> > > >> the
> > > >> class like the following:
> > > >>
> > > 
> > >httpClient.getHttpConnectionManager().getParams().setSoTimeout(1000*60*2);
> > > >>
> > > 
> > >httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(1000*
> > > >> 60*2);
> > > >>
> > > >> In one of the methods in the class, I catch a SocketTimeoutException 
> >and
> > > >> close resources in the finally clause.
> > > >> try
> > > >> {
> > > >> GetMethod getMethodObject = new GetMethod(DATA_URL);
> > > >> int statusCode = httpClient.executeMethod(getMethodObject);
> > > >> responseBody = getMethodObject.getResponseBodyAsStream();
> > > >> reader = new BufferedReader(new InputStreamReader(responseBody));
> > > >>
> > > >> String line= "";
> > > >> while( (line = reader.readLine()) != null )
> > > >> {
> > > >> ...
> > > >> }
> > > >> }
> > > >> catch(...)
> > > >> ...
> > > >> finally
> > > >> {
> > > >> if( reader != null )
> > > >> {
> > > >> try { reader.close(); }
> > > >> catch (Exception ex) { logger.warning("Could not close
> > > >> BufferedReader:"+ex);}
> > > >> }
> > > >>
> > > >> if( responseBody != null )
> > > >> {
> > > >> try { responseBody.close(); }
> > > >> catch (Exception ex) { logger.warning("Could not close InputStream 
> >from
> > > >> the server."); }
> > > >> }
> > > >>
> > > >> if( getMethodObject != null )
> > > >> {
> > > >> try { getMethodObject.releaseConnection(); }
> > > >> catch (Exception ex) { logger.warning("Could not release 
> >connection.");
> > > >}
> > > >> }
> > > >> }
> > > >>
> > > >> Once in a while when I get a SocketTimeoutException, I get the 
> >message
> > > >> could not close BufferedReader.
> > > >> These are the messages that I get:
> > > >> "Could not Close BufferedReader: java.net.SocketException:Connection
> > > >Reset."
> > > >> "Could not Close BufferedReader: java.net.SocketTimeoutException:Read
> > > >> Timeout."
> > > >>
> > > >> In other programs that use the same program flow, I get this message:
> > > >> "Could not Close BufferedReader: CRLF expected at the end of chunk"
> > > >>
> > > >> These exceptions seem to happen randomly. I'm wondering what is going 
> >on
> > > >> with these exceptions.  Could somebody please advise?
> > > >>
> > > >> Is there a way to get around all these exceptions?
> > > >>
> > > >
> > >
> > > >
> > > >> Thanks in advance for all the help.
> > > >> I really appreciate it.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to