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:com.cndatacom.ordersystem.manager.RetryHandler.java

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) {
        // Do not retry if over max retry count
        retry = false;/*from w  w w . ja  v  a 2s  . c  o m*/
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

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

    return retry;
}

From source file:com.google.httputils.RetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry;

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

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;/*from  www. j  ava2  s . c o  m*/
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // 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;
    } else {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        String requestType = currentReq.getMethod();
        if (!requestType.equals("POST")) {
            retry = true;
        } else {
            // otherwise do not retry
            retry = false;
        }
    }

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

    return retry;
}

From source file:com.blazeroni.reddit.http.RetryHandler.java

public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry;

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

    if (executionCount > this.maxRetries) {
        // Do not retry if over max retry count
        retry = false;//w  w  w  . j a  v  a2s.c  o  m
    } else if (EXCEPTION_MAP.containsKey(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        // immediately retry if error is whitelisted
        return EXCEPTION_MAP.get(exception.getClass());
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    } else {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        String requestType = currentReq.getMethod();
        if (!requestType.equals("POST")) {
            retry = true;
        } else {
            // otherwise do not retry
            retry = false;
        }
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        Log.debug("Not retrying request", exception);
    }

    return retry;
}

From source file:com.example.wechatsample.library.http.RetryHandler.java

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) {
        // Do not retry if over max retry count
        retry = false;//from w w w . jav  a 2  s.  co m
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

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

    return retry;
}

From source file:com.damytech.HttpConn.RetryHandler.java

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) {
        // Do not retry if over max retry count
        retry = false;//  w ww.  ja  va2  s.  c o  m
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // 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
        HttpRequest currentReq = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        /*String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");*/
        retry = !(currentReq instanceof HttpEntityEnclosingRequest);
    }

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

    return retry;
}

From source file:com.uwindsor.elgg.project.http.RetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

    boolean retry;

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

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;/*from www.j  ava 2s . c o m*/
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // 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;
    } else {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        String requestType = currentReq.getMethod();
        if (!requestType.equals("POST")) {
            retry = true;
        } else {
            // otherwise do not retry
            retry = false;
        }
    }

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

    return retry;
}

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

@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) {
        // Do not retry if over max retry count
        retry = false;//from ww  w.jav  a 2  s  . c  om
    } 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

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

    return retry;
}

From source file:com.android.pchelper.http.RetryHandler.java

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) {
        // Do not retry if over max retry count
        retry = false;/*w  w  w  . ja v a2 s .  c o  m*/
    } 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

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

    return retry;
}

From source file:com.DGSD.DGUtils.Http.BetterHttpRequestRetryHandler.java

public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry;

    this.timesRetried = executionCount;

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

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;//from   w  ww  .j  a  v  a2s. c o  m
    } else if (exceptionBlacklist.contains(exception.getClass())) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (exceptionWhitelist.contains(exception.getClass())) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for all other errors, retry only if request hasn't been fully sent yet
        // TODO: refine to resend all idempotent requests
        retry = true;
    } else {
        // otherwise do not retry
        retry = false;
    }

    if (retry) {
        Log.e(BetterHttp.LOG_TAG,
                "request failed (" + exception.getClass().getCanonicalName() + ": " + exception.getMessage()
                        + " / attempt " + executionCount + "), will retry in "
                        + RETRY_SLEEP_TIME_MILLIS / 1000.0 + " seconds");
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        Log.e(BetterHttp.LOG_TAG, "request failed after " + executionCount + " attempts");
        exception.printStackTrace();
    }

    return retry;
}

From source file:cn.caimatou.canting.utils.http.asynchttp.RetryHandler.java

@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) {
        // Do not retry if over max retry count
        retry = false;/*from ww w . j ava 2s.c o  m*/
    } 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

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

    return retry;
}