當前位置: 首頁>>代碼示例>>Java>>正文


Java PoolingHttpClientConnectionManager.setDefaultConnectionConfig方法代碼示例

本文整理匯總了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setDefaultConnectionConfig方法的典型用法代碼示例。如果您正苦於以下問題:Java PoolingHttpClientConnectionManager.setDefaultConnectionConfig方法的具體用法?Java PoolingHttpClientConnectionManager.setDefaultConnectionConfig怎麽用?Java PoolingHttpClientConnectionManager.setDefaultConnectionConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.conn.PoolingHttpClientConnectionManager的用法示例。


在下文中一共展示了PoolingHttpClientConnectionManager.setDefaultConnectionConfig方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
public HttpClientConnectionManager create(final HttpClientSettings settings) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings);

    final PoolingHttpClientConnectionManager cm = new
            PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf),
            null,
            DefaultSchemePortResolver.INSTANCE,
            new DelegatingDnsResolver(settings.getDnsResolver()),
            settings.getConnectionPoolTTL(),
            TimeUnit.MILLISECONDS);

    cm.setValidateAfterInactivity(settings.getValidateAfterInactivityMillis());
    cm.setDefaultMaxPerRoute(settings.getMaxConnections());
    cm.setMaxTotal(settings.getMaxConnections());
    cm.setDefaultSocketConfig(buildSocketConfig(settings));
    cm.setDefaultConnectionConfig(buildConnectionConfig(settings));

    return cm;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:22,代碼來源:ApacheConnectionManagerFactory.java

示例2: client

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
private static CloseableHttpClient client() {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(100);
    cm.setMaxTotal(400);

    MessageConstraints messageConstraints = MessageConstraints.custom()
            .setMaxHeaderCount(200)
            .setMaxLineLength(2000)
            .build();

    ConnectionConfig connectionConfig = ConnectionConfig.custom()
            .setMalformedInputAction(CodingErrorAction.IGNORE)
            .setUnmappableInputAction(CodingErrorAction.IGNORE)
            .setCharset(Consts.UTF_8)
            .setMessageConstraints(messageConstraints)
            .build();

    RequestConfig defaultRequestConfig = RequestConfig.custom()
            .setSocketTimeout(5000)
            .setConnectTimeout(5000)
            .setConnectionRequestTimeout(5000)
            .build();

    cm.setDefaultConnectionConfig(connectionConfig);

    return HttpClients.custom()
            .setConnectionManager(cm)
            .setDefaultRequestConfig(defaultRequestConfig)
            .build();
}
 
開發者ID:qiyu-kefu,項目名稱:message_interface,代碼行數:31,代碼來源:HttpClientPool.java

示例3: createHttpClientConnPool

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
 * 創建 HttpClient 連接池.
 *
 * @param connectionConfig
 * @return
 */
private PoolingHttpClientConnectionManager createHttpClientConnPool(ConnectionConfig connectionConfig) {
    PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(
            RegistryBuilder.<ConnectionSocketFactory>create().
                    register("http", PlainConnectionSocketFactory.getSocketFactory()).
                    register("https", buildSSLConn()).build());
    httpClientConnectionManager.setMaxTotal(MAX_TOTAL); // 設置連接池線程最大數量
    httpClientConnectionManager.setDefaultMaxPerRoute(MAX_ROUTE_TOTAL); // 設置單個路由最大的連接線程數量
    httpClientConnectionManager.setDefaultConnectionConfig(connectionConfig);
    return httpClientConnectionManager;
}
 
開發者ID:asdf2014,項目名稱:yuzhouwan,代碼行數:17,代碼來源:HttpUtils.java

示例4: createHttpClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
private CloseableHttpClient createHttpClient() throws NSPException {
	try {
		initSocketFactory();

		DnsResolver dnsResolver = new SystemDefaultDnsResolver() {
			public InetAddress[] resolve(String host)
					throws UnknownHostException {
				if (host.equalsIgnoreCase("localhost")) {
					return new InetAddress[] { InetAddress
							.getByAddress(new byte[] { 127, 0, 0, 1 }) };
				}

				return super.resolve(host);
			}
		};
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
				this.socketFactoryRegistry, dnsResolver);

		SocketConfig socketConfig = SocketConfig.custom()
				.setTcpNoDelay(true).setSoKeepAlive(true).setSoLinger(0)
				.setSoReuseAddress(true).build();

		connManager.setDefaultSocketConfig(socketConfig);

		ConnectionConfig connectionConfig = ConnectionConfig.custom()
				.setCharset(Consts.UTF_8).build();
		connManager.setDefaultConnectionConfig(connectionConfig);
		connManager.setConnectionConfig(new HttpHost("localhost", 80),
				ConnectionConfig.DEFAULT);

		connManager.setMaxTotal(this.mMaxConnections);

		if ((this.mMaxConnections <= this.mConnectionsPerRoute)
				&& (this.mMaxConnections > 0)) {
			this.mConnectionsPerRoute = this.mMaxConnections;
		}

		connManager.setDefaultMaxPerRoute(this.mConnectionsPerRoute);

		connManager.setMaxPerRoute(new HttpRoute(new HttpHost("localhost",
				80)), 100);

		CloseableHttpClient httpclient = HttpClients
				.custom()
				.setConnectionManager(connManager)
				.setDefaultRequestConfig(
						RequestConfig.copy(defaultRequestConfig).build())
				.build();

		return ((CloseableHttpClient) new WeakReference(httpclient).get());
	} catch (Exception e) {
		throw new NSPException(2, "Service unavailable.", e);
	}
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:55,代碼來源:HttpConnectionAdaptor.java

示例5: buildClient

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
protected ExecREST buildClient(RESTPool pool) throws IOException {
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getDefault();
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    }

    Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();

    //TODO buffers size
    SocketConfig socketConfig = SocketConfig.custom()
            .setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
            .setTcpNoDelay(true)
            .setSoKeepAlive(true)
            .setSoReuseAddress(true)
            .build();

    ConnectionConfig connectionConfig = ConnectionConfig.custom()
            .setCharset(StandardCharsets.UTF_8)
            .setMalformedInputAction(CodingErrorAction.IGNORE)
            .setUnmappableInputAction(CodingErrorAction.IGNORE)
            .build();

    HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
            new DefaultHttpRequestWriterFactory(),
            new DefaultHttpResponseParserFactory()
    );

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
            .setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
            .setExpectContinueEnabled(pool.expectContinue())
            .build();


    PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(socketRegistry, connFactory);

    ccm.setMaxTotal(pool.getMaxTotal());
    ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
    ccm.setDefaultSocketConfig(socketConfig);
    ccm.setDefaultConnectionConfig(connectionConfig);
    ccm.setValidateAfterInactivity(pool.getValidationOnInactivity());

    HttpClientBuilder builder = HttpClients.custom()
            .setConnectionManager(ccm)
            .setDefaultRequestConfig(requestConfig)
            .disableAutomaticRetries()
            .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
            .disableCookieManagement()
            .disableContentCompression();

    addProxy(pool, builder);

    handleRedirects(pool, builder);

    CloseableHttpClient servClient = builder.build();

    IdleConnectionEvictor evictor = new IdleConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);

    HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCSyncClientMonitor(pool.getName(), ccm) : null;

    return new HTTPCClient(servClient, evictor, monitor);
}
 
開發者ID:mercadolibre,項目名稱:java-restclient,代碼行數:69,代碼來源:HTTPCBuilder.java


注:本文中的org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setDefaultConnectionConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。