List of usage examples for org.apache.http.client.protocol HttpClientContext isRequestSent
public boolean isRequestSent()
From source file:com.mashape.galileo.agent.network.AnalyticsRetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { Args.notNull(exception, "Exception parameter"); Args.notNull(context, "HTTP context"); if (executionCount > this.retryCount) { return false; }//from w w w. j ava 2s . co m if (this.nonRetriableClasses.contains(exception.getClass())) { return false; } else { for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) { if (rejectException.isInstance(exception)) { return false; } } } if (exception instanceof NoHttpResponseException | exception instanceof SocketException | exception instanceof NoHttpResponseException) { LOGGER.warn(String.format("flush rquest failed, Agent will try to resend the request. reson: (%s)", exception.getMessage())); return true; } final HttpClientContext clientContext = HttpClientContext.adapt(context); if (!clientContext.isRequestSent()) { LOGGER.debug("Agent will try to resend the request."); return true; } return false; }
From source file:com.plutext.converter.MyRetryHandler.java
/** * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine * if the given method should be retried. *//*from w w w. j a v a 2 s.c o m*/ public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) { Args.notNull(exception, "Exception parameter"); Args.notNull(context, "HTTP context"); if (executionCount > this.retryCount) { // Do not retry if over max retry count return false; } if (this.nonRetriableClasses.contains(exception.getClass())) { return false; } else { for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) { if (rejectException.isInstance(exception)) { return false; } } } final HttpClientContext clientContext = HttpClientContext.adapt(context); final HttpRequest request = clientContext.getRequest(); if (requestIsAborted(request)) { return false; } try { System.out.println("sleeping " + executionCount); Thread.sleep(RETRY_SLEEP_TIME * executionCount); } catch (InterruptedException e) { e.printStackTrace(); } if (handleAsIdempotent(request)) { // Retry if the request is considered idempotent System.out.println("retry handleAsIdempotent " + executionCount); return true; } if (!clientContext.isRequestSent() || this.requestSentRetryEnabled) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent System.out.println("retry " + executionCount); return true; } // otherwise do not retry System.out.println("do not retry " + exception.getClass().getName() + exception.getMessage()); return false; }
From source file:com.github.horrorho.liquiddonkey.http.PersistentHttpRequestRetryHandler.java
boolean doRetryRequest(final IOException exception, final int executionCount, final HttpContext context) { HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); if (executionCount > retryCount) { logger.debug("-- doRetryRequest() > {} {} > false (limit)", request.getRequestLine(), exception.toString());/*from ww w . ja v a2 s. c om*/ return false; } if (exception instanceof SSLException) { logger.debug("-- doRetryRequest() > {} {} > false (SSLException)", request.getRequestLine(), exception.toString()); return false; } if (exception instanceof UnknownHostException && retryCount > 3) { logger.debug("-- doRetryRequest() > {} {} > UnknownHostException sleep({})", request.getRequestLine(), exception.toString(), retryDelayMs); sleep(timeOutMs); } if (retryCount > 3) { logger.debug("-- doRetryRequest() > {} {} > sleep({})", request.getRequestLine(), exception.toString(), retryDelayMs); sleep(timeOutMs); } if (!(request instanceof HttpEntityEnclosingRequest)) { logger.debug("-- doRetryRequest() > {} {} > true (idempotent)", request.getRequestLine(), exception.toString()); return true; } if (!clientContext.isRequestSent() || requestSentRetryEnabled) { logger.debug("-- doRetryRequest() > {} {} > true (non-idempotent)", request.getRequestLine(), exception.toString()); return true; } logger.debug("-- doRetryRequest() : {} >> {} > false (non-idempotent)", request.getRequestLine(), exception.toString()); return false; }