• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CachingHttpClientBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.http.impl.client.cache.CachingHttpClientBuilder的典型用法代码示例。如果您正苦于以下问题:Java CachingHttpClientBuilder类的具体用法?Java CachingHttpClientBuilder怎么用?Java CachingHttpClientBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CachingHttpClientBuilder类属于org.apache.http.impl.client.cache包,在下文中一共展示了CachingHttpClientBuilder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getHttpClientBuilder

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
public static HttpClientBuilder getHttpClientBuilder() {
	// Common CacheConfig for both the JarCacheStorage and the underlying
	// BasicHttpCacheStorage
	final CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(1024 * 128)
			.build();

	RequestConfig config = RequestConfig.custom().setConnectTimeout(DEFAULT_TIMEOUT)
			.setConnectionRequestTimeout(DEFAULT_TIMEOUT).setSocketTimeout(DEFAULT_TIMEOUT).build();

	HttpClientBuilder clientBuilder = CachingHttpClientBuilder.create()
			// allow caching
			.setCacheConfig(cacheConfig)
			// Wrap the local JarCacheStorage around a BasicHttpCacheStorage
			.setHttpCacheStorage(new JarCacheStorage(null, cacheConfig, new BasicHttpCacheStorage(cacheConfig)))
			// Support compressed data
			// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
			.addInterceptorFirst(new RequestAcceptEncoding()).addInterceptorFirst(new ResponseContentEncoding())
			// use system defaults for proxy etc.
			.useSystemProperties().setDefaultRequestConfig(config);
	return clientBuilder;
}
 
开发者ID:ansell,项目名称:csvsum,代码行数:22,代码来源:JSONUtil.java


示例2: newClosableCachingHttpClient

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
   final CacheConfig cacheConfig = CacheConfig.custom()
         .setMaxCacheEntries(Integer.MAX_VALUE)
         .setMaxObjectSize(Integer.MAX_VALUE)
         .build();

   settings.getCacheDirectory()
         .mkdirs();

   return CachingHttpClientBuilder.create()
         .setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
         .setCacheConfig(cacheConfig)
         .setDefaultRequestConfig(requestConfig(settings))
         .setDefaultCredentialsProvider(credentialsProvider(settings))
         .setRedirectStrategy(new LaxRedirectStrategy())
         .setRetryHandler(new StandardHttpRequestRetryHandler())
         .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
         .setConnectionManagerShared(true)

         .build();
}
 
开发者ID:Qyotta,项目名称:axon-eventstore,代码行数:22,代码来源:HttpClientFactory.java


示例3: setupProxy

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
@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;
	
}
 
开发者ID:eclipse,项目名称:thym,代码行数:20,代码来源:HttpUtil.java


示例4: testDescribeRdfCached

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
@Test
public void testDescribeRdfCached() throws IOException {
    try (final CloseableHttpClient cachClient = CachingHttpClientBuilder.create().setCacheConfig(DEFAULT).build()) {
        final String location = getLocation(postObjMethod());
        try (final CloseableHttpResponse response = cachClient.execute(new HttpGet(location))) {
            assertEquals("Client didn't return a OK!", OK.getStatusCode(), getStatus(response));
            logger.debug("Found HTTP headers:\n{}", asList(response.getAllHeaders()));
            assertTrue("Didn't find Last-Modified header!", response.containsHeader("Last-Modified"));
            final String lastModed = response.getFirstHeader("Last-Modified").getValue();
            final String etag = response.getFirstHeader("ETag").getValue();
            final HttpGet getObjMethod2 = new HttpGet(location);
            getObjMethod2.setHeader("If-Modified-Since", lastModed);
            getObjMethod2.setHeader("If-None-Match", etag);
            assertEquals("Client didn't get a NOT_MODIFIED!", NOT_MODIFIED.getStatusCode(),
                    getStatus(getObjMethod2));
        }
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:19,代码来源:FedoraLdpIT.java


示例5: tex2json

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
private static String tex2json(String tex) throws IOException {
    CachingHttpClientBuilder cachingHttpClientBuilder = CachingHttpClientBuilder.create();
    CacheConfig cacheCfg = new CacheConfig();
    cacheCfg.setMaxCacheEntries(100000);
    cacheCfg.setMaxObjectSize(8192);
    cachingHttpClientBuilder.setCacheConfig(cacheCfg);
    HttpClient client = cachingHttpClientBuilder.build();
    //HttpPost post = new HttpPost("http://localhost/convert");
    HttpPost post = new HttpPost("https://drmf-latexml.wmflabs.org");
    List<NameValuePair> nameValuePairs = new ArrayList<>(1);
    nameValuePairs.add(new BasicNameValuePair("tex",
        "$" + tex + "$"));
    //WARNING: This does not produce pmml, since there is a xstl trasformation that rewrites the output and removes pmml
//	      nameValuePairs.add(new BasicNameValuePair("profile",
//		          "mwsquery"));
    nameValuePairs.add(new BasicNameValuePair("preload",
        "mws.sty"));
    nameValuePairs.add(new BasicNameValuePair("profile",
        "math"));
    nameValuePairs.add(new BasicNameValuePair("noplane1",
        ""));
    nameValuePairs.add(new BasicNameValuePair("whatsout",
        "math"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
    HttpResponse response = client.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line = "";
    String result = "";
    while ((line = rd.readLine()) != null) {
      result += line;
    }
    return result;
  }
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:34,代码来源:TeX2MathML.java


示例6: getHttpClient

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的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


示例7: buildClient

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
/**
 * Builds the HTTP client to connect to the server.
 * 
 * @param trustSelfSigned <tt>true</tt> if the client should accept
 *            self-signed certificates
 * @return a new client instance
 */
private CloseableHttpClient buildClient(boolean trustSelfSigned) {
	try {
		// if required, define custom SSL context allowing self-signed certs
		SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault()
			: SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

		// set timeouts for the HTTP client
		int globalTimeout = readFromProperty("bdTimeout", 100000);
		int connectTimeout = readFromProperty("bdConnectTimeout", globalTimeout);
		int connectionRequestTimeout = readFromProperty("bdConnectionRequestTimeout", globalTimeout);
		int socketTimeout = readFromProperty("bdSocketTimeout", globalTimeout);
		RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT).setConnectTimeout(connectTimeout)
			.setSocketTimeout(socketTimeout).setConnectionRequestTimeout(connectionRequestTimeout).build();

		// configure caching
		CacheConfig cacheConfig = CacheConfig.copy(CacheConfig.DEFAULT).setSharedCache(false).setMaxCacheEntries(1000)
			.setMaxObjectSize(2 * 1024 * 1024).build();

		// configure connection pooling
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(RegistryBuilder
			.<ConnectionSocketFactory> create().register("http", PlainConnectionSocketFactory.getSocketFactory())
			.register("https", new SSLConnectionSocketFactory(sslContext)).build());
		int connectionLimit = readFromProperty("bdMaxConnections", 40);
		// there's only one server to connect to, so max per route matters
		connManager.setMaxTotal(connectionLimit);
		connManager.setDefaultMaxPerRoute(connectionLimit);

		// create the HTTP client
		return CachingHttpClientBuilder.create().setCacheConfig(cacheConfig).setDefaultRequestConfig(requestConfig)
			.setConnectionManager(connManager).build();
	} catch (GeneralSecurityException e) {
		throw new InternalConfigurationException("Failed to set up SSL context", e);
	}
}
 
开发者ID:BellaDati,项目名称:belladati-sdk-java,代码行数:42,代码来源:BellaDatiClient.java


示例8: buildHttpClient

import org.apache.http.impl.client.cache.CachingHttpClientBuilder; //导入依赖的package包/类
@SuppressWarnings("resource")
private static YamjHttpClient buildHttpClient() {
    LOG.trace("Create new YAMJ http client");
    
    // create proxy
    HttpHost proxy = null;
    CredentialsProvider credentialsProvider = null;
    
    if (StringUtils.isNotBlank(PROXY_HOST) && PROXY_PORT > 0) {
        proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
      
        if (StringUtils.isNotBlank(PROXY_USERNAME) && StringUtils.isNotBlank(PROXY_PASSWORD)) {
            credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(
                    new AuthScope(PROXY_HOST, PROXY_PORT),
                    new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_PASSWORD));
        }
    }

    
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT_SOCKET).build());
    connManager.setMaxTotal(20);
    connManager.setDefaultMaxPerRoute(2);
    
    CacheConfig cacheConfig = CacheConfig.custom()
                    .setMaxCacheEntries(1000)
                    .setMaxObjectSize(8192)
                    .build();
    
    HttpClientBuilder builder = CachingHttpClientBuilder.create()
            .setCacheConfig(cacheConfig)
            .setConnectionManager(connManager)
            .setProxy(proxy)
            .setDefaultCredentialsProvider(credentialsProvider)
            .setDefaultRequestConfig(RequestConfig.custom()
                    .setConnectionRequestTimeout(TIMEOUT_READ)
                    .setConnectTimeout(TIMEOUT_CONNECT)
                    .setSocketTimeout(TIMEOUT_SOCKET)
                    .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                    .setProxy(proxy)
                    .build());

    // show status
    showStatus();
    
    // build the client
    YamjHttpClient wrapper = new YamjHttpClient(builder.build(), connManager);
    wrapper.setUserAgentSelector(new WebBrowserUserAgentSelector());
    wrapper.addGroupLimit(".*", 1); // default limit, can be overwritten
    
    // First we have to read/create the rules
    String maxDownloadSlots = PropertiesUtil.getProperty("mjb.MaxDownloadSlots");
    if (StringUtils.isNotBlank(maxDownloadSlots)) {
        LOG.debug("Using download limits: {}", maxDownloadSlots);

        Pattern pattern = Pattern.compile(",?\\s*([^=]+)=(\\d+)");
        Matcher matcher = pattern.matcher(maxDownloadSlots);
        while (matcher.find()) {
            String group = matcher.group(1);
            try {
                final Integer maxResults = Integer.valueOf(matcher.group(2));
                wrapper.addGroupLimit(group, maxResults);
                LOG.trace("Added download slot '{}' with max results {}", group, maxResults);
            } catch (NumberFormatException error) {
                LOG.debug("Rule '{}' is no valid regexp, ignored", group);
            }
        }
    }
    
    return wrapper;
}
 
开发者ID:YAMJ,项目名称:yamj-v2,代码行数:73,代码来源:YamjHttpClientBuilder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OpcUaClient类代码示例发布时间:2022-05-23
下一篇:
Java CaptureManager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap