2010-12-01 32 views
5

は、私は、Apache HTTPコモンズDefaultHttpClientと建設後、私はそのリトライハンドラを設定していますを使用してい呼び出されることはありません私のexecute()コールのcatchでは、IOエラー、「操作がタイムアウトしました」が表示されますが、「リトライハンドラはコンソール出力のlogステートメントの例外を受け取りました」というメッセージは表示されません。私のリクエストはすべてPOSTリクエストですが、それらは冪等であり、悪影響を受けることなく複数回呼び出すことは安全です。ApacheはHttpClientをHttpRequestRetryHandlerは

再試行ハンドラを正しく設定していませんか?リトライハンドラは特定のシナリオでのみ呼び出されますか?あなたのハンドラで例外的なケースを扱っている場合はtrue HttpRequestRetryHandler

答えて

0

してみてください。

例外がスローされないようにする必要があります。

また、ハンドラでタイムアウト例外を処理することもできます。

httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { 
       @Override 
       public boolean retryRequest(final IOException ioe, 
         final int numRetry, final HttpContext context) 
       { 
        Log.d(TAG, "retry handler received exception of type: " + ioe.getClass().getName() + ", num retries: " + numRetry); 
        if (numRetry > 4) { // 3 retries 
         return false; 
        } 
        // Some exceptions we can retry without knowledge of which methods are being invoked 
        if (ioe instanceof NoHttpResponseException 
          || ioe instanceof UnknownHostException 
          || ioe instanceof SocketException 
          // Replace with the actual type of the exception 
          || ioe instanceof TimeoutException) { 
            return true; 
        } 
        return false; 
       } 
     }); 
1

のサブクラスリターンであるDefaultHttpRequestRetryHandlerを使用する

+0

残念ながら私はもはやプロジェクトのソースコードにアクセスすることができませんので、試してみることはできません。 – skyler

関連する問題