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


Java PoolingHttpClientConnectionManager类代码示例

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


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

示例1: afterPropertiesSet

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
@PostConstruct
public void afterPropertiesSet() throws Exception {
	RegistryBuilder<ConnectionSocketFactory> schemeRegistry = RegistryBuilder.create();

	schemeRegistry.register("http", PlainConnectionSocketFactory.getSocketFactory());

	SSLContext sslcontext = SSLContext.getInstance("TLS");
	sslcontext.init(new KeyManager[0], new TrustManager[]{new SimpleTrustManager()}, null);
	SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);
	schemeRegistry.register("https", sf);

	pool = new PoolingHttpClientConnectionManager(schemeRegistry.build());
	pool.setMaxTotal(maxConnection);
	pool.setDefaultMaxPerRoute(maxConnection);
	pool.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(sotimeout).build());
}
 
开发者ID:funtl,项目名称:framework,代码行数:17,代码来源:HttpClientUtil.java

示例2: getConnctionManager

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public static PoolingHttpClientConnectionManager getConnctionManager(){

        Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
        try {
            SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
                        new TrustAllHostNameVerifier());
            socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory> create()
                    .register("http", new PlainConnectionSocketFactory())
                    .register("https", trustSelfSignedSocketFactory)
                    .build();
        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
            Data.logger.warn("", e);
        }
        
        PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ? 
                new PoolingHttpClientConnectionManager(socketFactoryRegistry):
                new PoolingHttpClientConnectionManager();
        
        // twitter specific options
        cm.setMaxTotal(2000);
        cm.setDefaultMaxPerRoute(200);
        
        return cm;
    }
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:27,代码来源:ClientConnection.java

示例3: testHttpRequestGet

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
@Test
public void testHttpRequestGet() throws Exception {

    RequestConfig.Builder req = RequestConfig.custom();
    req.setConnectTimeout(5000);
    req.setConnectionRequestTimeout(5000);
    req.setRedirectsEnabled(false);
    req.setSocketTimeout(5000);
    req.setExpectContinueEnabled(false);

    HttpGet get = new HttpGet("http://127.0.0.1:54322/login");
    get.setConfig(req.build());

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(5);

    HttpClientBuilder builder = HttpClients.custom();
    builder.disableAutomaticRetries();
    builder.disableRedirectHandling();
    builder.setConnectionTimeToLive(5, TimeUnit.SECONDS);
    builder.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
    builder.setConnectionManager(cm);
    CloseableHttpClient client = builder.build();

    String s = client.execute(get, new ResponseHandler<String>() {

        @Override
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            assertEquals(301, response.getStatusLine().getStatusCode());
            return "success";
        }

    });
    assertEquals("success", s);

}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:37,代码来源:HTTPStrictTransportSecurityIT.java

示例4: createConnectionManager

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
protected HttpClientConnectionManager createConnectionManager(Registry<ConnectionSocketFactory> registry, int maxTotalConnections, int connectionsPerRoute) {
    // setup the connection live time
    PoolingHttpClientConnectionManager answer = 
        new PoolingHttpClientConnectionManager(registry, null, null, null, getConnectionTimeToLive(), TimeUnit.MILLISECONDS);
    int localMaxTotalConnections = maxTotalConnections;
    if (localMaxTotalConnections == 0) {
        localMaxTotalConnections = getMaxTotalConnections();
    }
    if (localMaxTotalConnections > 0) {
        answer.setMaxTotal(localMaxTotalConnections);
    }
    int localConnectionsPerRoute = connectionsPerRoute;
    if (localConnectionsPerRoute == 0) {
        localConnectionsPerRoute = getConnectionsPerRoute();
    }
    if (localConnectionsPerRoute > 0) {
        answer.setDefaultMaxPerRoute(localConnectionsPerRoute);
    }
    LOG.info("Created ClientConnectionManager " + answer);

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HttpComponent.java

示例5: OAuthHttpClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public OAuthHttpClient(int maxConnection, int connectTimeout, int socketTimeout) {
    PoolingHttpClientConnectionManager connectionManager =
            new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", SSLConnectionSocketFactory.getSocketFactory())
                    .build());
    // set max connection
    connectionManager.setMaxTotal(maxConnection);

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(connectTimeout)
            .setSocketTimeout(socketTimeout)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .build();

    httpClient = HttpClientBuilder.create()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig)
            .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
            .build();
}
 
开发者ID:xiaomi-passport,项目名称:oauth-java-sdk,代码行数:22,代码来源:OAuthHttpClient.java

示例6: DefaultConnector

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
/**
 * 
 */
public DefaultConnector() {
	final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
	cm.closeIdleConnections(120, TimeUnit.SECONDS);

	// would be nice to set this from outside -> keep alive
	final SocketConfig sConfig = SocketConfig.custom().setSoKeepAlive(true).setSoTimeout(Context.SOCKET_TO).build();
	cm.setDefaultSocketConfig(sConfig);

	cm.setMaxTotal(150);
	cm.setDefaultMaxPerRoute(150);
	cm.setValidateAfterInactivity(0);

	final HttpRequestRetryHandler rh = new DefaultHttpRequestRetryHandler(3, true);
	httpClient = HttpClients.custom().setRetryHandler(rh).setConnectionManager(cm).build();
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:19,代码来源:DefaultConnector.java

示例7: init

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public void init() {
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
		/* 配置同时支持 HTTP 和 HTPPS */
		Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
				.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
		/* 初始化连接管理器 */
		poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
		poolConnManager.setMaxTotal(maxTotal);
		poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
				.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
		httpClient = getConnection();
		log.info("HttpConnectionManager初始化完成...");
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:21,代码来源:HttpConnectionManager.java

示例8: test

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public static void test(){
		PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
		// Increase max total connection to 200  
		cm.setMaxTotal(200);  
		// Increase default max connection per route to 20  
		cm.setDefaultMaxPerRoute(20);  
		// Increase max connections for localhost:80 to 50  
		HttpHost localhost = new HttpHost("http://cc.0071515.com", 80);  
		cm.setMaxPerRoute(new HttpRoute(localhost), 2);  
		  
//		CloseableHttpClient httpClient = HttpClients.custom()  
//		        .setConnectionManager(cm)  
//		        .build();  
		httpClient = HttpClients.custom()  
				.setConnectionManager(cm)  
				.build();  
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:18,代码来源:HttpTest.java

示例9: createDefaultHttpClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
protected CloseableHttpClient createDefaultHttpClient() {
	
	PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
	cm.setMaxTotal(maxConnections);
	cm.setDefaultMaxPerRoute(maxConnections);
	
   Builder config = RequestConfig.custom()
			.setConnectionRequestTimeout(connectionRequestTimeout)
			.setConnectTimeout(connectTimeout)
			.setSocketTimeout(socketTimeout);

      // TODO: Set Credentials
	CloseableHttpClient httpClient = HttpClients.custom()
	        .setConnectionManager(cm).setDefaultRequestConfig(config.build())
	        .build();
	return httpClient;		
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:18,代码来源:CurrentGraphVersionCacheImpl.java

示例10: getPool

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public HttpClient getPool() {

		PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
		HttpClientBuilder builder = HttpClientBuilder.create();
		connectionManager.setMaxTotal(maxConnections);
		connectionManager.setDefaultMaxPerRoute(maxConnections);
		RequestConfig config = RequestConfig.custom()
				.setConnectTimeout(timeOut)
				.setConnectionRequestTimeout(timeOut).setSocketTimeout(timeOut)
				.build();
		connectionMonitor = new IdleConnectionMonitorThread(connectionManager);
		connectionMonitor.start();
		builder.setConnectionManager(connectionManager);
		builder.setKeepAliveStrategy(myStrategy);
		CloseableHttpClient defaultHttpClient = builder
				.setDefaultRequestConfig(config).build();
		logger.debug("prepared client");
		return defaultHttpClient;
	}
 
开发者ID:zafar142007,项目名称:FolderSync,代码行数:20,代码来源:Auth.java

示例11: httpsGet

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public static String httpsGet(String getUrl, String defaultCharset, Map<String, String> headerParas)
		throws KeyManagementException, NoSuchAlgorithmException {
	// 采用绕过验证的方式处理https请求
	SSLContext sslcontext = createIgnoreVerifySSL();

	// 设置协议http和https对应的处理socket链接工厂的对象
	Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
			.register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext))
			.build();
	PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
	HttpClients.custom().setConnectionManager(connManager);

	// 创建自定义的httpclient对象
	CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager).build();

	return getInner(getUrl, defaultCharset, headerParas, httpclient);
}
 
开发者ID:rongwei84n,项目名称:Auts_Assert_manager,代码行数:18,代码来源:PhicommHttpClient.java

示例12: initPoolingHttpClientManager

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
private void initPoolingHttpClientManager () {
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("https", SSLConnectionSocketFactory.getSocketFactory())
            .register("http", PlainConnectionSocketFactory.getSocketFactory()).build();

    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connectionManager.setMaxTotal(MAX_CONNECTION);
    connectionManager.setDefaultMaxPerRoute(MAX_CONNECTION_PER_ROUTE);

    final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)
            .setConnectionRequestTimeout(CONNECTION_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT);

    final RequestConfig requestConfig = requestConfigBuilder.build();

    HashSet<Header> defaultHeaders = new HashSet<Header>();
    defaultHeaders.add(new BasicHeader(HttpHeaders.PRAGMA, "no-cache"));
    defaultHeaders.add(new BasicHeader(HttpHeaders.CACHE_CONTROL, "no-cache"));

    final HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultHeaders(defaultHeaders).disableAuthCaching().disableContentCompression();
    this.httpClient = httpClientBuilder.setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:22,代码来源:IlluminatiHttpClient.java

示例13: getCustomClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
/**
 * custom http client for server with SSL errors
 *
 * @return
 */
public final CloseableHttpClient getCustomClient() {
    try {
        HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
                (TrustStrategy) (X509Certificate[] arg0, String arg1) -> true).build();
        builder.setSSLContext(sslContext);
        HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory)
                .build();
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        builder.setConnectionManager(connMgr);
        return builder.build();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return getSystemClient();
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:26,代码来源:AbstractHttpClient.java

示例14: create

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
public HttpClientConnectionManager create(ApacheSdkHttpClientFactory configuration,
                                          AttributeMap standardOptions) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(standardOptions);

    final PoolingHttpClientConnectionManager cm = new
            PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf),
            null,
            DefaultSchemePortResolver.INSTANCE,
            null,
            configuration.connectionTimeToLive().orElse(Defaults.CONNECTION_POOL_TTL).toMillis(),
            TimeUnit.MILLISECONDS);

    cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setDefaultSocketConfig(buildSocketConfig(standardOptions));

    return cm;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:ApacheConnectionManagerFactory.java

示例15: InternalPredictionService

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入依赖的package包/类
@Autowired
public InternalPredictionService(AppProperties appProperties){
    this.appProperties = appProperties;
    connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(150);
    connectionManager.setDefaultMaxPerRoute(150);
    
    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT)
            .setConnectTimeout(DEFAULT_CON_TIMEOUT)
            .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();
    
    httpClient = HttpClients.custom()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig)
            .setRetryHandler(new HttpRetryHandler())
            .build();
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:19,代码来源:InternalPredictionService.java


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