当前位置: 首页>>代码示例>>Java>>正文


Java CachingHttpClients类代码示例

本文整理汇总了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();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:21,代码来源:MCRURIResolver.java

示例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();
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:20,代码来源:SAClient.java

示例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());
}
 
开发者ID:brutusin,项目名称:Brutusin-RPC,代码行数:30,代码来源:HttpEndpoint.java

示例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"));
    }
 
开发者ID:soluvas,项目名称:soluvas-scrape,代码行数:10,代码来源:ScrapeConfig.java

示例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();
}
 
开发者ID:eclipse,项目名称:thym,代码行数:16,代码来源:HttpUtil.java

示例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;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:44,代码来源:HttpClientConfiguration.java

示例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");
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:5,代码来源:LastModified.java

示例8: httpClient

import org.apache.http.impl.client.cache.CachingHttpClients; //导入依赖的package包/类
@Bean(destroyMethod = "close")
public CloseableHttpClient httpClient() {
    return CachingHttpClients.custom().useSystemProperties().build();
}
 
开发者ID:lumenrobot,项目名称:lumen,代码行数:5,代码来源:HttpClientConfig.java

示例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();
}
 
开发者ID:thelinmichael,项目名称:spotify-web-api-java,代码行数:48,代码来源:SpotifyHttpManager.java


注:本文中的org.apache.http.impl.client.cache.CachingHttpClients类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。