2010-12-01 68 views
5

我使用了Apache HTTP公共DefaultHttpClient和施工後,我設置了重傳處理器:Apache的HttpClient的HttpRequestRetryHandler從未引用


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) { 
        } 
        return false; 
       } 
     }); 

,我送我的請求,經常超時的服務器,在我的execute()調用的catch中,我收到一個IO錯誤,「操作超時」,但是我從來沒有在控制檯輸出中看到任何「重試處理程序接收到類型」log語句的異常。我的所有請求都是POST請求,但它們是冪等的 - 它們可以安全地多次調用而沒有不良的副作用。

我是否設置了錯誤的重試處理程序?是否僅在某些情況下調用重試處理程序?

回答

0

嘗試使用DefaultHttpRequestRetryHandler這是HttpRequestRetryHandler

1

,則返回true的子類,如果你在處理你的處理器的例外情況。

這應該保持從拋出的異常。

您也可以在處理程序中處理Timeout異常。

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; 
       } 
     }); 
+0

不幸的是我不再有權限訪問項目源代碼,所以我不能試用這個。 – skyler 2013-07-09 15:03:24

相關問題