本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}