Example usage for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT

List of usage examples for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT

Introduction

In this page you can find the example usage for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT.

Prototype

String HTTP_REQ_SENT

To view the source code for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT.

Click Source Link

Usage

From source file:org.robam.xutils.http.client.RetryHandler.java

/**
 * @param exception/*  w w w.  jav a  2  s  .  c  o m*/
 * @param retriedTimes
 * @param context      HTTP,??,ActivityContext
 * @return
 */
@Override
public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) {
    boolean retry = true;

    if (exception == null || context == null) {
        return false;
    }

    // ?????,?,True
    Object isReqSent = context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = isReqSent == null ? false : (Boolean) isReqSent;

    // ???
    if (retriedTimes > maxRetries) {
        // ??,
        retry = false;
    } else if (exceptionBlackList.contains(exception.getClass())) {
        // ?BlackList???.
        retry = false;
    } else if (exceptionWhiteList.contains(exception.getClass())) {
        // ?????.
        retry = true;
    } else if (!sent) {
        // ??
        retry = true;
    }

    if (retry) {
        try {
            Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST);
            if (currRequest != null) {
                if (currRequest instanceof HttpRequestBase) {
                    // ???GET?retry,?GET,??
                    HttpRequestBase requestBase = (HttpRequestBase) currRequest;
                    retry = "GET".equals(requestBase.getMethod());
                } else if (currRequest instanceof RequestWrapper) {
                    RequestWrapper requestWrapper = (RequestWrapper) currRequest;
                    retry = "GET".equals(requestWrapper.getMethod());
                }
            } else {
                retry = false;
                LogUtils.e("retry error, curr request is null");
            }
        } catch (Throwable e) {
            retry = false;
            LogUtils.e("retry error", e);
        }
    }

    if (retry) {
        // sleep a while and retry http request again.
        SystemClock.sleep(RETRY_SLEEP_INTERVAL);
    }

    return retry;
}

From source file:com.ab.http.RetryHandler.java

/**
 * ??TODO//from   w w w.  ja v a 2s.  c  om
 * @see org.apache.http.client.HttpRequestRetryHandler#retryRequest(java.io.IOException, int, org.apache.http.protocol.HttpContext)
 * @author: zhaoqp
 * @date2013-10-22 ?4:23:15
 * @version v1.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);

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:httpfailover.DefaultFailoverRetryHandler.java

public boolean tryNextHost(final IOException exception, final HttpContext context) {

    if (exception == null) {
        throw new IllegalArgumentException("Exception parameter may not be null");
    }//w w  w.j av a  2 s  . c  o  m

    HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);

    if (requestIsAborted(request)) {
        return false;
    }

    if (handleAsIdempotent(request)) {
        // Retry if the request is considered idempotent
        return true;
    }

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (!sent || this.requestSentRetryEnabled) {
        // Retry if the request has not been sent fully or
        // if it's OK to retry methods that have been sent
        return true;
    }
    // otherwise do not retry
    return false;
}

From source file:com.lurencun.cfuture09.androidkit.http.async.RetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    // ??/*from  w  w  w  . j av  a2s. c o m*/
    boolean retry = true;

    // ?
    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b.booleanValue());

    if (executionCount > maxRetries) {
        // ????
        retry = false;
    } else if (isInList(exceptionBlacklist, exception)) {
        // ??????
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // ????
        retry = true;
    } else if (!sent) {
        // ?????
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
        log.w(exception);
    }
    return retry;
}

From source file:com.fheebiy.http.lite.apache.DefaultHttpRequestRetryHandler.java

protected boolean retryRequest(final HttpContext context) {
    final HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
    final Object obj = context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    final boolean isSent = obj == null ? false : (Boolean) obj;

    if (requestIsAborted(request)) {
        return false;
    }//from w  ww  . j a v  a2 s . c  o m

    if (handleAsIdempotent(request)) {
        // Retry if the request is considered idempotent
        return true;
    }
    if (!isSent || this.requestSentRetryEnabled) {
        // Retry if the request has not been sent fully or
        // if it's OK to retry methods that have been sent
        return true;
    }
    return false;
}