org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy Java Examples

The following examples show how to use org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AviRestUtils.java    From sdk with Apache License 2.0 6 votes vote down vote up
public static CloseableHttpClient buildHttpClient(AviCredentials creds) {
	CloseableHttpClient httpClient = null;
	if (!creds.getVerify()) {
		SSLContext sslcontext = null;
		try {
			sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
		} catch (Exception e) {
			e.printStackTrace();
		}

		SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslcontext,
				(s, sslSession) -> true);

		httpClient = HttpClients.custom().setRetryHandler(retryHandler(creds))
				.setSSLSocketFactory(sslConnectionSocketFactory)
				.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(
						creds.getNumApiRetries(), creds.getRetryWaitTime())).disableCookieManagement()
				.build();
	} else {
		httpClient = HttpClients.custom().setRetryHandler(retryHandler(creds))
				.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(
						creds.getNumApiRetries(), creds.getRetryWaitTime())).disableCookieManagement()
				.build();
	}
	return httpClient;
}
 
Example #2
Source File: DropWizardWebsocketsTest.java    From dropwizard-websockets with MIT License 6 votes vote down vote up
@Before
    public void setUp() throws Exception {

        this.client = HttpClients.custom()
                .setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 2000))
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(10000)
                        .setConnectTimeout(10000)
                        .setConnectionRequestTimeout(10000)
                        .build()).build();
        this.om = new ObjectMapper();
        this.wsClient = ClientManager.createClient();
        wsClient.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 10000);        
            if (System.getProperty(TRAVIS_ENV) != null) {
                System.out.println("waiting for Travis machine");
                waitUrlAvailable(String.format("http://%s:%d/api?name=foo", LOCALHOST, PORT));
//                Thread.sleep(1); // Ugly sleep to debug travis            
            }
    }
 
Example #3
Source File: HttpClientFactory.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private ServiceUnavailableRetryStrategy createServiceUnavailableRetryStrategy() {
    return new DefaultServiceUnavailableRetryStrategy(3, 2000);
}
 
Example #4
Source File: ShutdownClientFactory.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private ServiceUnavailableRetryStrategy createServiceUnavailableRetryStrategy() {
    return new DefaultServiceUnavailableRetryStrategy(RETRY_COUNT, RETRY_INTERVAL_IN_MILLIS);
}