Java 类org.apache.http.impl.client.cache.CachingHttpClients 实例源码

项目:mycore    文件:MCRURIResolver.java   
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();
}
项目:dmaap-framework    文件:SAClient.java   
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();
}
项目:Brutusin-RPC    文件:HttpEndpoint.java   
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());
}
项目:soluvas-scrape    文件:ScrapeConfig.java   
@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"));
    }
项目:thym    文件:HttpUtil.java   
@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();
}
项目:sentry    文件:HttpClientConfiguration.java   
@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;
}
项目:kowalski    文件:LastModified.java   
public LastModified(File cache) {
    this.client = CachingHttpClients.custom().setCacheDir(cache).useSystemProperties().build();
    this.format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
}
项目:sentry    文件:HttpClientConfiguration.java   
@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;
}
项目:lumen    文件:HttpClientConfig.java   
@Bean(destroyMethod = "close")
public CloseableHttpClient httpClient() {
    return CachingHttpClients.custom().useSystemProperties().build();
}
项目:spotify-web-api-java    文件:SpotifyHttpManager.java   
/**
 * 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();
}