2010-12-01 7 views
5

내가 아파치 HTTP 공유지 DefaultHttpClient 건설 후, 나는 그것의 재시도 핸들러를 설정하고있어 사용하고 호출되지 않습니다 내 execute() 호출의 catch에서 IO 오류, "작업 시간 초과"가 표시되지만 콘솔 출력에서 ​​"재시도 핸들러가 예외 유형의"로그 명령문을받지 못합니다. 모든 요청은 POST 요청이지만 멱등하지 않습니다. 불리한 부작용없이 여러 번 호출하는 것이 안전합니다.아파치 HttpClient를 HttpRequestRetryHandler는

재시도 핸들러를 잘못 설정 했습니까? 재시도 핸들러는 특정 시나리오에서만 호출됩니까?

답변

0

시도는 당신이 당신의 핸들러에서 예외적 인 경우를 처리하는 경우 HttpRequestRetryHandler

1

반환 사실의 서브 클래스입니다 DefaultHttpRequestRetryHandler를 사용합니다.

예외가 throw되는 것을 방지해야합니다.

또한 처리기에서 시간 초과 예외도 처리 할 수 ​​있습니다.

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

관련 문제