org.apache.http.impl.client.cache.CachingHttpClientBuilder Java Examples

The following examples show how to use org.apache.http.impl.client.cache.CachingHttpClientBuilder. 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: HttpClientFactory.java    From riptide with MIT License 6 votes vote down vote up
private static HttpClientBuilder configureCaching(final Caching caching,
        @Nullable final Object cacheStorage) {
    final Heuristic heuristic = caching.getHeuristic();

    final CacheConfig.Builder config = CacheConfig.custom()
            .setSharedCache(caching.getShared())
            .setMaxObjectSize(caching.getMaxObjectSize())
            .setMaxCacheEntries(caching.getMaxCacheEntries());

    if (heuristic.getEnabled()) {
        config.setHeuristicCachingEnabled(true);
        config.setHeuristicCoefficient(heuristic.getCoefficient());
        config.setHeuristicDefaultLifetime(heuristic.getDefaultLifeTime().to(TimeUnit.SECONDS));
    }

    @Hack("return cast tricks classloader in case of missing httpclient-cache")
    CachingHttpClientBuilder builder = CachingHttpClients.custom()
                                                         .setCacheConfig(config.build())
                                                         .setHttpCacheStorage((HttpCacheStorage) cacheStorage)
                                                         .setCacheDir(Optional.ofNullable(caching.getDirectory())
                                                                              .map(Path::toFile)
                                                                              .orElse(null));
    return HttpClientBuilder.class.cast(builder);
}
 
Example #2
Source File: HttpUtil.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("restriction")
private static CachingHttpClientBuilder setupProxy(CachingHttpClientBuilder builder, URI url){
	final IProxyService proxyService = HybridCore.getDefault().getProxyService();
	if(proxyService != null ){
		IProxyData[] proxies = proxyService.select(url);
		if(proxies != null && proxies.length > 0){
			IProxyData proxy = proxies[0];
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			if(proxy.isRequiresAuthentication()){
				credsProvider.setCredentials(new AuthScope(proxy.getHost(), proxy.getPort()), 
						new UsernamePasswordCredentials(proxy.getUserId(), proxy.getPassword()));
			}
			builder.setDefaultCredentialsProvider(credsProvider);
			builder.setProxy(new HttpHost(proxy.getHost(), proxy.getPort()));
		}
	}
	return builder;
	
}
 
Example #3
Source File: HttpUtil.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("restriction")
private static CloseableHttpClient getHttpClient(URI url){
	CacheConfig cacheConfig = CacheConfig.custom()
       	.setMaxCacheEntries(1000)
       	.setMaxObjectSize(120*1024).setHeuristicCachingEnabled(true)
       	.setHeuristicDefaultLifetime(TimeUnit.HOURS.toSeconds(12))
       	.build();
	
	CachingHttpClientBuilder builder = CachingHttpClients.custom()
			.setCacheConfig(cacheConfig)
			.setHttpCacheStorage(new BundleHttpCacheStorage(HybridCore.getContext().getBundle()));
	
	builder = setupProxy(builder, url);
	return builder.build();
}
 
Example #4
Source File: TracingCachingHttpClientBuilder.java    From brave with Apache License 2.0 4 votes vote down vote up
public static CachingHttpClientBuilder create(Tracing tracing) {
  return new TracingCachingHttpClientBuilder(HttpTracing.create(tracing));
}
 
Example #5
Source File: TracingCachingHttpClientBuilder.java    From brave with Apache License 2.0 4 votes vote down vote up
public static CachingHttpClientBuilder create(HttpTracing httpTracing) {
  return new TracingCachingHttpClientBuilder(httpTracing);
}