commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Max Johnson" <max.john...@flytxt.com>
Subject RE: HttpClient stability issues?
Date Fri, 23 May 2003 12:55:50 GMT
You need to recycle your POST method before you perform a retry attempt. So
your catch block would look something like this:

  catch (HttpRecoverableException e) {
	logInfo( "A recoverable exception occurred, retrying." + e);
	method.recycle();
	method.setPath(url.toString());
  }

Alpha 3 build has problems though so it's worth upgrading to the latest
nightly build too.

Max

-----Original Message-----
From: Walther, Benjamin [mailto:Benjamin.Walther@sunrise.net]
Sent: 23 May 2003 13:42
To: 'commons-httpclient-dev@jakarta.apache.org';
'commons-user@jakarta.apache.org'
Subject: HttpClient stability issues?


Hi,


I use httpclient like described in the tutorial. I have a session scoped
class that creates a httpclient instance upon creation time. It then nvokes
methods on this client instance.

Unfortunately it behaves very unstable. I use the releasse 2.0 alpha 3 .
When invoking the execute method  i get
IOException: broken pipe or org.apache.commons.httpclient.HttpException:
Already used, but not recycled.
Any idea?
My code looks like:
public void doPost(URL url, String postBody, Writer writer ) throws
IOException {
PostMethod method = new PostMethod(url.toString());
		try {
			method.setRequestBody( postBody );
// Execute the method.
			int statusCode = -1;
			int attempt = 0;
			// We will retry up to 3 times.
			while (statusCode == -1 && attempt < 3) {
			  try {
				// execute the method.
				statusCode = client.executeMethod(method);
				attempt++;
			  }
			  catch (HttpRecoverableException e) {
				logInfo( "A recoverable exception occurred,
retrying." + e);
			  }
			  catch (IOException e) {
				logError("Failed to connect to
url:"+url.toString()+" Error:"+e);
				throw e;
			  }
			}
			// Check that we didn't run out of retries.

			if ( statusCode != HttpStatus.SC_OK){
				if (statusCode == -1) {
				  logError("Failed to recover from
exception. See info.log");
				}
				//Vitria sends only HttpStatus.SC_OK back
when no error therefore no action here
				logInfo("Status from Vitria not OK(200).
Status was:"+statusCode);
			}

			// Deal with the response.
		   // Use caution: ensure correct character encoding and is
not binary data
		   copyStreamToCharWriter(method.getResponseBodyAsStream(),
writer);
		   logDebug( "HttpConnectionManager.doPost: Response from
url:"+url.toString()+":"+writer.toString());
		}
		finally {
			// Release the connection.
				method.releaseConnection();
		}
}



Mime
View raw message