use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project sling by apache.
the class TopologyConnectorClient method createHttpClient.
private CloseableHttpClient createHttpClient() {
final HttpClientBuilder builder = HttpClientBuilder.create();
// setting the SoTimeout (which is configured in seconds)
builder.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(1000 * config.getSoTimeout()).build());
builder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return builder.build();
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project docker-maven-plugin by fabric8io.
the class HttpPingChecker method ping.
private boolean ping() throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(HTTP_PING_TIMEOUT).setConnectTimeout(HTTP_PING_TIMEOUT).setConnectionRequestTimeout(HTTP_PING_TIMEOUT).setRedirectsEnabled(false).build();
CloseableHttpClient httpClient;
if (allowAllHosts) {
SSLContextBuilder builder = new SSLContextBuilder();
try {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)).setSSLSocketFactory(socketFactory).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new IOException("Unable to set self signed strategy on http wait: " + e, e);
}
} else {
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false)).build();
}
try {
CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build());
try {
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode == 501) {
throw new IllegalArgumentException("Invalid or not supported HTTP method '" + method.toUpperCase() + "' for checking " + url);
}
return responseCode >= statusMin && responseCode <= statusMax;
} finally {
response.close();
}
} finally {
httpClient.close();
}
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project cuba by cuba-platform.
the class IdpServiceLogoutCallbackInvoker method performLogoutOnServiceProviders.
public void performLogoutOnServiceProviders(String idpSessionId) {
List<String> serviceProviderLogoutUrls = idpConfig.getServiceProviderLogoutUrls();
asyncServiceLogoutExecutor.submit(() -> {
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager).setRetryHandler(new DefaultHttpRequestRetryHandler(3, true)).build();
try {
for (String serviceProviderLogoutUrl : serviceProviderLogoutUrls) {
callLoggedOutServiceUrl(client, serviceProviderLogoutUrl, idpSessionId);
}
} catch (Throwable ex) {
log.error("Unable to perform logout on IDP services for session {}", idpSessionId, ex);
} finally {
connectionManager.shutdown();
}
});
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project java by wavefrontHQ.
the class AbstractAgent method createAgentService.
/**
* Create RESTeasy proxies for remote calls via HTTP.
*/
protected WavefrontAPI createAgentService() {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.registerProvider(JsonNodeWriter.class);
if (!factory.getClasses().contains(ResteasyJackson2Provider.class)) {
factory.registerProvider(ResteasyJackson2Provider.class);
}
if (httpUserAgent == null) {
httpUserAgent = "Wavefront-Proxy/" + props.getString("build.version");
}
ClientHttpEngine httpEngine;
if (javaNetConnection) {
httpEngine = new JavaNetConnectionEngine() {
@Override
protected HttpURLConnection createConnection(ClientInvocation request) throws IOException {
HttpURLConnection connection = (HttpURLConnection) request.getUri().toURL().openConnection();
connection.setRequestProperty("User-Agent", httpUserAgent);
connection.setRequestMethod(request.getMethod());
// 5s
connection.setConnectTimeout(httpConnectTimeout);
// 60s
connection.setReadTimeout(httpRequestTimeout);
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection secureConnection = (HttpsURLConnection) connection;
secureConnection.setSSLSocketFactory(new SSLSocketFactoryImpl(HttpsURLConnection.getDefaultSSLSocketFactory(), httpRequestTimeout));
}
return connection;
}
};
} else {
HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(httpUserAgent).setMaxConnTotal(httpMaxConnTotal).setMaxConnPerRoute(httpMaxConnPerRoute).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(httpRequestTimeout).build()).setSSLSocketFactory(new SSLConnectionSocketFactoryImpl(SSLConnectionSocketFactory.getSystemSocketFactory(), httpRequestTimeout)).setRetryHandler(new DefaultHttpRequestRetryHandler(httpAutoRetries, true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(httpConnectTimeout).setConnectionRequestTimeout(httpConnectTimeout).setSocketTimeout(httpRequestTimeout).build()).build();
final ApacheHttpClient4Engine apacheHttpClient4Engine = new ApacheHttpClient4Engine(httpClient, true);
// avoid using disk at all
apacheHttpClient4Engine.setFileUploadInMemoryThresholdLimit(100);
apacheHttpClient4Engine.setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit.MB);
httpEngine = apacheHttpClient4Engine;
}
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(factory).register(GZIPDecodingInterceptor.class).register(gzipCompression ? GZIPEncodingInterceptor.class : DisableGZIPEncodingInterceptor.class).register(AcceptEncodingGZIPFilter.class).build();
ResteasyWebTarget target = client.target(server);
return target.proxy(WavefrontAPI.class);
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project jenkin-qtest-plugin by QASymphony.
the class HttpClientUtils method getHttpClient.
public static HttpClient getHttpClient(String hostUrl) throws Exception {
int timeout;
try {
timeout = Integer.parseInt(System.getenv("SOCKET_TIMEOUT"));
} catch (Exception e) {
timeout = DEFAULT_SOCKET_TIMEOUT;
}
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().useSystemProperties();
setHttpProxy(httpClientBuilder, hostUrl);
SSLConnectionSocketFactory sslSocketFactory = getSslSocketFactory();
httpClientBuilder.setSSLSocketFactory(sslSocketFactory).setConnectionReuseStrategy(new NoConnectionReuseStrategy());
timeout = timeout * 1000;
httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).build());
httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(RETRY_MAX_COUNT, RETRY_REQUEST_SEND_RETRY_ENABLED) {
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
if (executionCount > this.getRetryCount())
return false;
if (exception instanceof HttpHostConnectException)
return true;
return super.retryRequest(exception, executionCount, context);
}
});
return httpClientBuilder.build();
}
Aggregations