List of usage examples for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT
String HTTP_REQ_SENT
To view the source code for org.apache.http.protocol ExecutionContext HTTP_REQ_SENT.
Click Source Link
From source file:yangqi.hc.HttpContextTest.java
/** * @param args//from ww w .j a v a 2s. c o m * @throws IOException * @throws ClientProtocolException */ public static void main(String[] args) throws ClientProtocolException, IOException { // TODO Auto-generated method stub HttpClient httpclient = new DefaultHttpClient(); HttpContext context = new BasicHttpContext(); // Prepare a request object HttpGet httpget = new HttpGet("http://www.apache.org/"); // Execute the request HttpResponse response = httpclient.execute(httpget, context); showAttr(ExecutionContext.HTTP_CONNECTION, context); showAttr(ExecutionContext.HTTP_PROXY_HOST, context); showAttr(ExecutionContext.HTTP_REQ_SENT, context); showAttr(ExecutionContext.HTTP_RESPONSE, context); showAttr(ExecutionContext.HTTP_REQUEST, context); showAttr(ExecutionContext.HTTP_TARGET_HOST, context); }
From source file:com.hippoapp.asyncmvp.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 > DEFAULT_MAX_RETRIES) { retry = false;// www . j av a 2 s. c o m } else if (sUnretriedExceptionSet.contains(exception.getClass())) { retry = false; } else if (sRetriedExceptionSet.contains(exception.getClass())) { 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_IN_MILLS); } else { exception.printStackTrace(); } return retry; }
From source file:cn.com.dfc.pl.afinal.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) { // ?5//from w w w .jav a2s . c o m 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); retry = currentReq != null && !"POST".equals(currentReq.getMethod()); } if (retry) { //1??? SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.my.cloudcontact.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) { // ?5// w ww .j av a 2 s. com 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); retry = currentReq != null && !"POST".equals(currentReq.getMethod()); } if (retry) { // 1??? SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.xc.framework.https.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }//from w w w .j av a 2s . c om 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())) { 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) { 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; Log.e("RetryHandler", "retry error, curr request is null"); } } catch (Throwable e) { retry = false; Log.e("retry error", "" + e); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry // http request again. } return retry; }
From source file:com.dongfang.net.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }//w w w . j a v a 2 s . c om Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (retriedTimes > maxRetries) { 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) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { 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; ULog.e("retry error, curr request is null"); } } catch (Throwable e) { retry = false; ULog.e("retry error", e); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry http request again. } return retry; }
From source file:com.android.idtt.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (retriedTimes > maxRetries) { // ?5/*from www . java2 s . co m*/ 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) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { HttpRequestBase requestBase = (HttpRequestBase) currRequest; retry = requestBase != null && "GET".equals(requestBase.getMethod()); } else if (currRequest instanceof RequestWrapper) { RequestWrapper requestWrapper = (RequestWrapper) currRequest; retry = requestWrapper != null && "GET".equals(requestWrapper.getMethod()); } } else { LogUtils.e("retry error, curr request is null"); } } catch (Exception e) { retry = false; LogUtils.e("retry error", e); } } if (retry) { //1??? SystemClock.sleep(RETRY_SLEEP_INTERVAL); } else { LogUtils.e(exception.getMessage(), exception); } return retry; }
From source file:cn.isif.util_plus.http.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }//from w w w. ja va 2 s. com 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())) { 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) { 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) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry http request again. } return retry; }
From source file:com.drive.student.xutils.http.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }/*from ww w . j a va2 s. c om*/ 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())) { 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) { 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) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry // http request again. } return retry; }
From source file:cn.salesuite.saf.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 > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w . j a v a 2 s . c om*/ } 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; }