Android アプリに HttpRequestRetryHandler を実装しようとしています。HttpRequestRetryHandler hereのドキュメントを読みました。
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {
public boolean retryRequest(
IOException exception,
int executionCount,
HttpContext context) {
if (executionCount >= 5) {
// Do not retry if over max retry count
return false;
}
if (exception instanceof InterruptedIOException) {
// Timeout
return false;
}
if (exception instanceof UnknownHostException) {
// Unknown host
return false;
}
if (exception instanceof ConnectException) {
// Connection refused
return false;
}
if (exception instanceof SSLException) {
// SSL handshake exception
return false;
}
HttpRequest request = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
if (idempotent) {
// Retry if the request is considered idempotent
return true;
}
return false;
}
};
httpclient.setHttpRequestRetryHandler(myRetryHandler);
ドキュメントの例では、特定の例外を再試行してはならないことが記載されています。たとえば、InterruptedIOException は再試行しないでください。
質問 1 InterruptedIOException を再試行してはならないのはなぜですか?
質問 2どの例外を再試行し、どの例外を再試行しないかを知る方法は? 例 - ConnectionTimeoutException と SocketTimeoutException を再試行する必要がありますか?
また、ドキュメントによると、HttpClient は、GET や HEAD などの非エンティティ エンクロージング メソッドは冪等であると想定し、POST や PUT などのエンティティ エンクロージング メソッドはそうではないと想定しています。
質問 3これは、POST および PUT メソッドを再試行してはならないということですか? そうでない場合、HttpPost リクエストを再試行するにはどうすればよいですか?