Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.DefaultHttpRequestRetryHandler


    @Test
    public void noRetryOnUnknownHost() throws Exception {
        HttpContext context = mock(HttpContext.class);
        HttpUriRequest request = mock(HttpUriRequest.class);

        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();

        when(request.isAborted()).thenReturn(Boolean.FALSE);
        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);

        Assert.assertFalse(retryHandler.retryRequest(new UnknownHostException(), 1, context));
    }
View Full Code Here


    @Test
    public void noRetryOnAbortedRequests() throws Exception{
        HttpContext context = mock(HttpContext.class);
        HttpUriRequest request = mock(HttpUriRequest.class);

        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();

        when(request.isAborted()).thenReturn(Boolean.TRUE);
        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);

        Assert.assertFalse(retryHandler.retryRequest(new IOException(),3,context));
    }
View Full Code Here

    public void retryOnNonAbortedRequests() throws Exception{

        HttpContext context = mock(HttpContext.class);
        HttpUriRequest request = mock(HttpUriRequest.class);

        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();

        when(request.isAborted()).thenReturn(Boolean.FALSE);
        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);

        Assert.assertTrue(retryHandler.retryRequest(new IOException(),3,context));
    }
View Full Code Here

    public void noRetryOnConnectionTimeout() throws Exception{

        HttpContext context = mock(HttpContext.class);
        HttpUriRequest request = mock(HttpUriRequest.class);

        DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();

        when(request.isAborted()).thenReturn(false);
        when(context.getAttribute(ExecutionContext.HTTP_REQUEST)).thenReturn(request);

        Assert.assertFalse(retryHandler.retryRequest(new ConnectTimeoutException(),3,context));
    }
View Full Code Here

   */
  public static final HttpClient getClient(int timeout) {
    HttpClientBuilder client = HttpClientBuilder.create();
    client.setConnectionManager(connectionManager);
    // dont retry
    client.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    // establish a connection within x seconds
    RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).build();
    client.setDefaultRequestConfig(config);
    // no redirects
    client.disableRedirectHandling();
View Full Code Here

        final ConnectionReuseStrategy reuseStrategy = keepAlive == 0
                ? new NoConnectionReuseStrategy()
                : new DefaultConnectionReuseStrategy();
        final HttpRequestRetryHandler retryHandler = configuration.getRetries() == 0
                ? NO_RETRIES
                : (httpRequestRetryHandler == null ? new DefaultHttpRequestRetryHandler(configuration.getRetries(),
                false) : httpRequestRetryHandler);

        final RequestConfig requestConfig
                = RequestConfig.custom().setCookieSpec(cookiePolicy)
                .setSocketTimeout(timeout)
View Full Code Here

            // Add as the first request interceptor
            client.addRequestInterceptor(new PreemptiveAuth(), 0);
        }
        boolean requestSentRetryEnabled = Boolean.parseBoolean(System.getProperty("requestSentRetryEnabled"));
        if(requestSentRetryEnabled){
            client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3,requestSentRetryEnabled));
        }
        // set the following user agent with each request
        String userAgent = "ArtifactoryBuildClient/" + CLIENT_VERSION;
        HttpProtocolParams.setUserAgent(client.getParams(), userAgent);
        return client;
View Full Code Here

      ConnRouteParams.setDefaultProxy(
          client.getParams(), new HttpHost(splits[0], Integer.parseInt(splits[1]), "http"));
    }

    // try resending the request once
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true));

    // Add hooks for gzip/deflate
    client.addRequestInterceptor(new HttpRequestInterceptor() {
      public void process(
          final org.apache.http.HttpRequest request,
View Full Code Here

        setSocketOperationTimeout(60000);
        setRequestTimeout(-1);
    }

    public void setRetryCount(int count) {
        httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(count, false));
    }
View Full Code Here

            default:
                throw new IllegalStateException("Method not defined!");
        }
       
        // Retry handler (no-retries):
        hcBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
       
        // Url:
        final URL url = IDNUtil.getIDNizedURL(request.getUrl());
        final String urlHost = url.getHost();
        final int urlPort = url.getPort()==-1?url.getDefaultPort():url.getPort();
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.DefaultHttpRequestRetryHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.