Skip to content

Commit

Permalink
modified httpclient to retry in case it received 500 internal server …
Browse files Browse the repository at this point in the history
…error

git-svn-id: http://yusuke.homeip.net/svn/twitter4j/trunk@275 117b7e0d-5933-0410-9d29-ab41bb01d86b
  • Loading branch information
yusuke committed May 7, 2009
1 parent 78a3031 commit dc97fe0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/twitter4j/http/HttpClient.java
Expand Up @@ -374,11 +374,11 @@ public Response get(String url) throws TwitterException {
}

//for test purpose
/*package*/ int retriedCount = 0;
/*package*/ String lastURL;

protected Response httpRequest(String url, PostParameter[] postParams,
boolean authenticated) throws TwitterException {
int retriedCount;
int retry = retryCount + 1;
Response res = null;
// update the status
Expand Down Expand Up @@ -428,11 +428,15 @@ protected Response httpRequest(String url, PostParameter[] postParams,
}
}
log(res.toString());
con.disconnect();
if (responseCode != OK) {
throw new TwitterException(getCause(responseCode) + "\n" + res.toString(), responseCode);
if (responseCode != INTERNAL_SERVER_ERROR || retriedCount == retryCount) {
throw new TwitterException(getCause(responseCode) + "\n" + res.toString(), responseCode);
}
// will retry if the status code is INTERNAL_SERVER_ERROR
} else {
break;
}
con.disconnect();
break;
} finally {
try {
is.close();
Expand Down

0 comments on commit dc97fe0

Please sign in to comment.