2010-12-01 13 views
5

मैं अपाचे HTTP कॉमन्स DefaultHttpClient और निर्माण के बाद, मैं अपने फिर से प्रयास करें हैंडलर सेट कर रहा हूं उपयोग कर रहा हूँ:अपाचे 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; 
       } 
     }); 

सर्वर है कि मैं अपने अनुरोध अक्सर समय समाप्त करने के लिए भेज रहा हूँ, और मेरे निष्पादन() कॉल के catch में, मुझे एक आईओ त्रुटि प्राप्त होती है, "ऑपरेशन का समय समाप्त हो गया" हालांकि मैं अपने कंसोल आउटपुट में किसी भी "पुनः प्रयास हैंडलर प्रकार का अपवाद" लॉग स्टेटमेंट कभी नहीं देखता। मेरे सभी अनुरोध POST अनुरोध हैं, लेकिन वे बेवकूफ हैं - प्रतिकूल दुष्प्रभावों के बिना वे कई बार कॉल करने के लिए सुरक्षित हैं।

क्या मैं पुनः प्रयास हैंडलर को गलत तरीके से स्थापित कर रहा हूं? क्या पुनः प्रयास हैंडलर केवल कुछ परिदृश्यों में शामिल है?

उत्तर

0

कोशिश DefaultHttpRequestRetryHandler जो HttpRequestRetryHandler

1

वापसी सच का एक उपवर्ग है अगर आप अपने हैंडलर में एक असाधारण मामला संभाला उपयोग करने के लिए।

इसे अपनाने से अपवाद को दूर रखना चाहिए।

इसके अलावा आप अपने हैंडलर में टाइमआउट अपवाद भी संभाल सकते हैं।

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

संबंधित मुद्दे