本文整理汇总了Java中org.apache.http.impl.client.cache.CachingHttpClients类的典型用法代码示例。如果您正苦于以下问题:Java CachingHttpClients类的具体用法?Java CachingHttpClients怎么用?Java CachingHttpClients使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CachingHttpClients类属于org.apache.http.impl.client.cache包,在下文中一共展示了CachingHttpClients类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MCRRESTResolver
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
public MCRRESTResolver() {
CacheConfig cacheConfig = CacheConfig.custom()
.setMaxObjectSize(MAX_OBJECT_SIZE)
.setMaxCacheEntries(MAX_CACHE_ENTRIES)
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(REQUEST_TIMEOUT)
.setSocketTimeout(REQUEST_TIMEOUT)
.build();
String userAgent = MessageFormat
.format("MyCoRe/{0} ({1}; java {2})", MCRCoreVersion.getCompleteVersion(), MCRConfiguration.instance()
.getString("MCR.NameOfProject", "undefined"), System.getProperty("java.version"));
this.restClient = CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setDefaultRequestConfig(requestConfig)
.setUserAgent(userAgent)
.build();
MCRShutdownHandler.getInstance().addCloseable(this::close);
this.logger = LogManager.getLogger();
}
示例2: createDefaultClient
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
private CloseableHttpClient createDefaultClient(HttpClientConnectionManager fClientCm) {
final CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(DEFAULT_CACHE_MAX_ENTRIES)
.setMaxObjectSize(DEFAULT_CACHE_MAX_OBJ_SIZE)
.setHeuristicCachingEnabled(true)
.setHeuristicDefaultLifetime(DEFAULT_CACHE_TTL_IN_SECS)
.build();
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(DEFAULT_REQUEST_CONN_TIMEOUT_IN_MS)
.setSocketTimeout(DEFAULT_REQUEST_SOCK_TIMEOUT_IN_MS)
.build();
return CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setConnectionManager(fClientCm)
.setDefaultRequestConfig(requestConfig)
.build();
}
示例3: HttpEndpoint
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
public HttpEndpoint(URI endpoint, Config cfg, HttpClientContextFactory clientContextFactory) {
if (endpoint == null) {
throw new IllegalArgumentException("Endpoint is required");
}
if (cfg == null) {
cfg = new ConfigurationBuilder().build();
}
CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(cfg.getMaxCacheEntries())
.setMaxObjectSize(cfg.getMaxCacheObjectSize())
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(1000 * cfg.getConnectTimeOutSeconds())
.setSocketTimeout(1000 * cfg.getSocketTimeOutSeconds())
.build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(cfg.getMaxConections());
this.endpoint = endpoint;
this.httpClient = CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new StandardHttpRequestRetryHandler())
.setConnectionManager(cm)
.build();
this.clientContextFactory = clientContextFactory;
initPingThread(cfg.getPingSeconds());
}
示例4: httpClient
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
@Bean(destroyMethod = "close")
public CloseableHttpClient httpClient() {
// final CacheConfig cacheConfig = CacheConfig.custom()
// .setMaxCacheEntries(1000)
// .setMaxObjectSize(16 * 1024 * 1024)
// .build();
// final ManagedHttpCacheStorage managedCache = new ManagedHttpCacheStorage(cacheConfig);
return CachingHttpClients.createFileBound(new File("cache/httpclient"));
}
示例5: getHttpClient
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
@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();
}
示例6: httpClient
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
@Bean
public CloseableHttpClient httpClient() {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(properties().getReadTimeout())
.setSocketTimeout(properties().getSocketTimeout())
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(properties().getMaxTotalConnections());
connectionManager.setDefaultMaxPerRoute(properties().getMaxConnectionsPerRoute());
CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(properties().getMaxCacheEntries())
.setMaxObjectSize(properties().getMaxObjectSize())
.setHeuristicCachingEnabled(true) // important!
.build();
File cacheDir = new File(properties().getCacheDir());
try {
Files.createDirectories(cacheDir.toPath());
} catch (IOException e) {
log.warn("Could not create cache directory - using temp folder", e);
try {
cacheDir = Files.createTempDirectory("cache").toFile();
} catch (IOException ee) {
log.warn("Could not create temp cache directory", ee);
}
}
FileResourceFactory resourceFactory = new FileResourceFactory(cacheDir);
cacheStorage = new ManagedHttpCacheStorage(cacheConfig);
client = CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setResourceFactory(resourceFactory)
.setHttpCacheStorage(cacheStorage)
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.setUserAgent(Constants.USER_AGENT)
.build();
return client;
}
示例7: LastModified
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
public LastModified(File cache) {
this.client = CachingHttpClients.custom().setCacheDir(cache).useSystemProperties().build();
this.format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
}
示例8: httpClient
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
@Bean(destroyMethod = "close")
public CloseableHttpClient httpClient() {
return CachingHttpClients.custom().useSystemProperties().build();
}
示例9: SpotifyHttpManager
import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
/**
* Construct a new SpotifyHttpManager instance.
*
* @param builder The builder.
*/
public SpotifyHttpManager(Builder builder) {
this.proxy = builder.proxy;
this.proxyCredentials = builder.proxyCredentials;
this.cacheMaxEntries = builder.cacheMaxEntries;
this.cacheMaxObjectSize = builder.cacheMaxObjectSize;
CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(cacheMaxEntries != null ? cacheMaxEntries : DEFAULT_CACHE_MAX_ENTRIES)
.setMaxObjectSize(cacheMaxEntries != null ? cacheMaxEntries : DEFAULT_CACHE_MAX_OBJECT_SIZE)
.setSharedCache(false)
.build();
ConnectionConfig connectionConfig = ConnectionConfig
.custom()
.setCharset(Charset.forName("UTF-8"))
.build();
new BasicCredentialsProvider();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (proxy != null) {
credentialsProvider.setCredentials(
new AuthScope(proxy.getHostName(), proxy.getPort(), null, proxy.getSchemeName()),
proxyCredentials
);
}
RequestConfig requestConfig = RequestConfig
.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setProxy(proxy)
.build();
httpClient = CachingHttpClients
.custom()
.setCacheConfig(cacheConfig)
.setDefaultConnectionConfig(connectionConfig)
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultRequestConfig(requestConfig)
.build();
}