Code example for HttpContext

Methods: getAttribute

0
 
    @Override 
    public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
        boolean retry = true;
 
        Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
        boolean sent = (b != null && b.booleanValue());
 
        if(executionCount > maxRetries) {
            // 尝试次数超过用户定义的测试,默认5次 
            retry = false;
        } else if (exceptionBlacklist.contains(exception.getClass())) {
            // 线程被用户中断,则不继续尝试 
            retry = false;
        } else if (exceptionWhitelist.contains(exception.getClass())) {
            retry = true;
        } else if (!sent) {
            retry = true;
        } 
 
        if(retry) {
            HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute( ExecutionContext.HTTP_REQUEST );
            String requestType = currentReq.getMethod();
            retry = !requestType.equals("POST");
        } 
 
        if(retry) {