本文整理汇总了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setDefaultSocketConfig方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingHttpClientConnectionManager.setDefaultSocketConfig方法的具体用法?Java PoolingHttpClientConnectionManager.setDefaultSocketConfig怎么用?Java PoolingHttpClientConnectionManager.setDefaultSocketConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.conn.PoolingHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingHttpClientConnectionManager.setDefaultSocketConfig方法的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());
}
示例2: 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();
}
示例3: 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;
}
示例4: 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;
}
示例5: init
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
/**
* 创建httpclient连接池,并初始化httpclient
*/
public void init() {
try {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null,
new TrustSelfSignedStrategy())
.build();
HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslsf)
.build();
httpClientConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
// Increase max total connection to 200
httpClientConnectionManager.setMaxTotal(maxTotalPool);
// Increase default max connection per route to 20
httpClientConnectionManager.setDefaultMaxPerRoute(maxConPerRoute);
SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(socketTimeout).build();
httpClientConnectionManager.setDefaultSocketConfig(socketConfig);
} catch (Exception e) {
}
}
示例6: createConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private HttpClientConnectionManager createConnectionManager() {
SocketConfig socketConfig = createSocketConfig();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(config.getThreadCount());
connectionManager.setDefaultMaxPerRoute(config.getThreadCount());
connectionManager.setDefaultSocketConfig(socketConfig);
return connectionManager;
}
示例7: SwiftConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
/**
* Default constructor
*
* @param connectionConfigurationT connection conf
*/
public SwiftConnectionManager(ConnectionConfiguration connectionConfigurationT) {
connectionConfiguration = connectionConfigurationT;
connectionPool = new PoolingHttpClientConnectionManager();
LOG.trace(
"SwiftConnectionManager: setDefaultMaxPerRoute {}",
connectionConfiguration.getMaxPerRoute()
);
connectionPool.setDefaultMaxPerRoute(connectionConfiguration.getMaxPerRoute());
LOG.trace(
"SwiftConnectionManager: getMaxTotal {}",
connectionConfiguration.getMaxTotal()
);
connectionPool.setMaxTotal(connectionConfiguration.getMaxTotal());
LOG.trace(
"Generate SocketConfig with soTimeout of {}",
connectionConfiguration.getSoTimeout()
);
SocketConfig socketConfig = SocketConfig.custom()
.setSoKeepAlive(false)
.setSoTimeout(connectionConfiguration.getSoTimeout())
.build();
connectionPool.setDefaultSocketConfig(socketConfig);
rConfig = RequestConfig.custom()
.setExpectContinueEnabled(true)
.setConnectTimeout(connectionConfiguration.getReqConnectTimeout())
.setConnectionRequestTimeout(
connectionConfiguration.getReqConnectionRequestTimeout())
.setSocketTimeout(connectionConfiguration.getReqSocketTimeout())
.build();
}
示例8: prepare
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private void prepare() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", this.plainConnectionSocketFactory)
.register("https", this.sslConnectionSocketFactory).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(this.maxTotalConn);
connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost);
connectionManager.setDefaultSocketConfig(SocketConfig.copy(SocketConfig.DEFAULT).setSoTimeout(this.soTimeout).build());
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(connectionManager, this.idleConnTimeout, this.checkWaitTime);
this.idleConnectionMonitorThread.setDaemon(true);
this.idleConnectionMonitorThread.start();
this.httpClientBuilder = HttpClients
.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(this.soTimeout)
.setConnectTimeout(this.connectionTimeout).setConnectionRequestTimeout(this.connectionRequestTimeout).build())
.setRetryHandler(this.httpRequestRetryHandler);
if (StringUtils.isNotBlank(this.httpProxyHost) && StringUtils.isNotBlank(this.httpProxyUsername)) {
// 使用代理服务器 需要用户认证的代理服务器
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(new AuthScope(this.httpProxyHost, this.httpProxyPort), new UsernamePasswordCredentials(this.httpProxyUsername, this.httpProxyPassword));
this.httpClientBuilder.setDefaultCredentialsProvider(provider);
}
if (StringUtils.isNotBlank(this.userAgent)) {
this.httpClientBuilder.setUserAgent(this.userAgent);
}
}
示例9: prepare
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private synchronized void prepare() {
if(prepared.get()){
return;
}
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", this.plainConnectionSocketFactory)
.register("https", this.sslConnectionSocketFactory)
.build();
@SuppressWarnings("resource")
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(this.maxTotalConn);
connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost);
connectionManager.setDefaultSocketConfig(
SocketConfig.copy(SocketConfig.DEFAULT)
.setSoTimeout(this.soTimeout)
.build()
);
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(
connectionManager, this.idleConnTimeout, this.checkWaitTime);
this.idleConnectionMonitorThread.setDaemon(true);
this.idleConnectionMonitorThread.start();
this.httpClientBuilder = HttpClients.custom()
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
.setDefaultRequestConfig(
RequestConfig.custom()
.setSocketTimeout(this.soTimeout)
.setConnectTimeout(this.connectionTimeout)
.setConnectionRequestTimeout(this.connectionRequestTimeout)
.build()
)
.setRetryHandler(this.httpRequestRetryHandler);
if (StringUtils.isNotBlank(this.httpProxyHost)
&& StringUtils.isNotBlank(this.httpProxyUsername)) {
// 使用代理服务器 需要用户认证的代理服务器
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(
new AuthScope(this.httpProxyHost, this.httpProxyPort),
new UsernamePasswordCredentials(this.httpProxyUsername,
this.httpProxyPassword));
this.httpClientBuilder.setDefaultCredentialsProvider(provider);
}
if (StringUtils.isNotBlank(this.userAgent)) {
this.httpClientBuilder.setUserAgent(this.userAgent);
}
prepared.set(true);
}
示例10: 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);
}
}
示例11: 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);
}
示例12: prepare
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private synchronized void prepare() {
if (prepared.get()) {
return;
}
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", this.plainConnectionSocketFactory)
.register("https", this.sslConnectionSocketFactory)
.build();
@SuppressWarnings("resource")
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(this.maxTotalConn);
connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost);
connectionManager.setDefaultSocketConfig(
SocketConfig.copy(SocketConfig.DEFAULT)
.setSoTimeout(this.soTimeout)
.build()
);
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(
connectionManager, this.idleConnTimeout, this.checkWaitTime);
this.idleConnectionMonitorThread.setDaemon(true);
this.idleConnectionMonitorThread.start();
HttpClientBuilder httpClientBuilder = HttpClients.custom()
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
.setSSLSocketFactory(this.buildSSLConnectionSocketFactory())
.setDefaultRequestConfig(
RequestConfig.custom()
.setSocketTimeout(this.soTimeout)
.setConnectTimeout(this.connectionTimeout)
.setConnectionRequestTimeout(this.connectionRequestTimeout)
.build()
)
.setRetryHandler(this.httpRequestRetryHandler);
if (StringUtils.isNotBlank(this.httpProxyHost)
&& StringUtils.isNotBlank(this.httpProxyUsername)) {
// 使用代理服务器 需要用户认证的代理服务器
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(
new AuthScope(this.httpProxyHost, this.httpProxyPort),
new UsernamePasswordCredentials(this.httpProxyUsername,
this.httpProxyPassword));
httpClientBuilder.setDefaultCredentialsProvider(provider);
}
if (StringUtils.isNotBlank(this.userAgent)) {
httpClientBuilder.setUserAgent(this.userAgent);
}
this.closeableHttpClient = httpClientBuilder.build();
prepared.set(true);
}
示例13: prepare
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private void prepare() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", this.plainConnectionSocketFactory)
.register("https", this.sslConnectionSocketFactory)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(this.maxTotalConn);
connectionManager.setDefaultMaxPerRoute(this.maxConnPerHost);
connectionManager.setDefaultSocketConfig(
SocketConfig.copy(SocketConfig.DEFAULT)
.setSoTimeout(this.soTimeout)
.build()
);
this.idleConnectionMonitorThread = new IdleConnectionMonitorThread(
connectionManager, this.idleConnTimeout, this.checkWaitTime);
this.idleConnectionMonitorThread.setDaemon(true);
this.idleConnectionMonitorThread.start();
this.httpClientBuilder = HttpClients.custom()
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
.setDefaultRequestConfig(
RequestConfig.custom()
.setSocketTimeout(this.soTimeout)
.setConnectTimeout(this.connectionTimeout)
.setConnectionRequestTimeout(this.connectionRequestTimeout)
.build()
)
.setRetryHandler(this.httpRequestRetryHandler);
if (StringUtils.isNotBlank(this.httpProxyHost)
&& StringUtils.isNotBlank(this.httpProxyUsername)) {
// 使用代理服务器 需要用户认证的代理服务器
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(
new AuthScope(this.httpProxyHost, this.httpProxyPort),
new UsernamePasswordCredentials(this.httpProxyUsername,
this.httpProxyPassword));
this.httpClientBuilder.setDefaultCredentialsProvider(provider);
}
if (StringUtils.isNotBlank(this.userAgent)) {
this.httpClientBuilder.setUserAgent(this.userAgent);
}
}
示例14: createClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private void createClient() {
try {
SSLContext sslContext;
SSLConnectionSocketFactory sslsf;
if (configuration.isDisableHttpsVerification()) {
sslContext = SSLContext.getInstance("SSL");
TrustManager mytm[] = {new MyTrustManager()};
sslContext.init(null, mytm, null);
sslsf = new SSLConnectionSocketFactory(
sslContext,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} else {
sslContext = SSLContexts.custom().build();
sslsf = new SSLConnectionSocketFactory(
sslContext,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory())
.register("https", sslsf)
.build();
poolManager = new PoolingHttpClientConnectionManager(r);
if (configuration.getMaxConnTotal() > 0) {
poolManager.setMaxTotal(configuration.getMaxConnTotal());
}
if (configuration.getMaxConnPerRoute() > 0) {
poolManager.setDefaultMaxPerRoute(configuration.getMaxConnPerRoute());
}
poolManager.setDefaultSocketConfig(SocketConfig.custom().setSoKeepAlive(true).setSoReuseAddress(true).setTcpNoDelay(false).setSoTimeout(configuration.getSotimeout()).build());
ConnectionKeepAliveStrategy myStrategy = (HttpResponse response, HttpContext context) -> configuration.getKeepAlive();
httpclient = HttpClients
.custom()
.setConnectionManager(poolManager)
.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE)
.setKeepAliveStrategy(myStrategy)
.build();
} catch (NoSuchAlgorithmException | KeyManagementException ex) {
throw new RuntimeException(ex);
}
}
示例15: buildHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的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;
}