You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Walther, Benjamin" <Be...@sunrise.net> on 2003/05/23 14:41:53 UTC
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();
}
}
Re: HttpClient stability issues?
Posted by Ortwin Glück <or...@nose.ch>.
Ben
You should upgrade to either a nightly build or beta-1 which will be
released within hours / days. Alpha-3 is not a good build as there are
several issues.
Odi
RE: HttpClient stability issues?
Posted by Max Johnson <ma...@flytxt.com>.
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();
}
}
RE: HttpClient stability issues?
Posted by Max Johnson <ma...@flytxt.com>.
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();
}
}