本文整理汇总了Java中org.apache.http.conn.HttpClientConnectionManager类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientConnectionManager类的具体用法?Java HttpClientConnectionManager怎么用?Java HttpClientConnectionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientConnectionManager类属于org.apache.http.conn包,在下文中一共展示了HttpClientConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的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: createConnectionManager
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的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;
}
示例3: create
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的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: if
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
/**
* Returns a wrapped instance of {@link HttpClientConnectionManager}
* to capture the necessary performance metrics.
*
* @param orig the target instance to be wrapped
*/
public static HttpClientConnectionManager wrap
(HttpClientConnectionManager orig) {
if (orig instanceof Wrapped)
throw new IllegalArgumentException();
final Class<?>[] interfaces;
if (orig instanceof ConnPoolControl) {
interfaces = new Class<?>[]{
HttpClientConnectionManager.class,
ConnPoolControl.class,
Wrapped.class
};
} else {
interfaces = new Class<?>[]{
HttpClientConnectionManager.class,
Wrapped.class
};
}
return (HttpClientConnectionManager) Proxy.newProxyInstance(
// https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423
ClientConnectionManagerFactory.class.getClassLoader(),
interfaces,
new Handler(orig));
}
示例5: autoShutdown
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
@Test
public void autoShutdown() throws Exception {
assertEquals(0, IdleConnectionReaper.size());
for (int i = 0; i < 3; i++) {
HttpClientConnectionManager m = new TestClientConnectionManager();
HttpClientConnectionManager m2 = new TestClientConnectionManager();
assertTrue(IdleConnectionReaper.registerConnectionManager(m));
assertEquals(1, IdleConnectionReaper.size());
assertTrue(IdleConnectionReaper.registerConnectionManager(m2));
assertEquals(2, IdleConnectionReaper.size());
assertTrue(IdleConnectionReaper.removeConnectionManager(m));
assertEquals(1, IdleConnectionReaper.size());
assertTrue(IdleConnectionReaper.removeConnectionManager(m2));
assertEquals(0, IdleConnectionReaper.size());
assertFalse(IdleConnectionReaper.shutdown());
}
}
示例6: getHttpClient
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
public static CloseableHttpClient getHttpClient(HttpClientConnectionManager connectionManager, int maxConnections) {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000).build();
ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build();
SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true)
.setSoReuseAddress(true).build();
String userAgent = MessageFormat
.format("MyCoRe/{0} ({1}; java {2})", MCRCoreVersion.getCompleteVersion(), MCRConfiguration.instance()
.getString("MCR.NameOfProject", "undefined"), System.getProperty("java.version"));
//setup http client
return HttpClients.custom().setConnectionManager(connectionManager)
.setUserAgent(userAgent).setRetryHandler(new MCRRetryHandler(maxConnections))
.setDefaultRequestConfig(requestConfig).setDefaultConnectionConfig(connectionConfig)
.setDefaultSocketConfig(socketConfig).build();
}
示例7: createDefaultClient
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
private CloseableHttpClient createDefaultClient(HttpClientConnectionManager fClientCm) {
final CacheConfig cacheConfig = CacheConfig.custom()
.setMaxCacheEntries(DEFAULT_CACHE_MAX_ENTRIES)
.setMaxObjectSize(DEFAULT_CACHE_MAX_OBJ_SIZE)
.setHeuristicCachingEnabled(true)
.setHeuristicDefaultLifetime(DEFAULT_CACHE_TTL_IN_SECS)
.build();
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(DEFAULT_REQUEST_CONN_TIMEOUT_IN_MS)
.setSocketTimeout(DEFAULT_REQUEST_SOCK_TIMEOUT_IN_MS)
.build();
return CachingHttpClients.custom()
.setCacheConfig(cacheConfig)
.setConnectionManager(fClientCm)
.setDefaultRequestConfig(requestConfig)
.build();
}
示例8: MinimalClientExec
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
public MinimalClientExec(
final HttpRequestExecutor requestExecutor,
final HttpClientConnectionManager connManager,
final ConnectionReuseStrategy reuseStrategy,
final ConnectionKeepAliveStrategy keepAliveStrategy) {
Args.notNull(requestExecutor, "HTTP request executor");
Args.notNull(connManager, "Client connection manager");
Args.notNull(reuseStrategy, "Connection reuse strategy");
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
this.httpProcessor = new ImmutableHttpProcessor(
new RequestContentHC4(),
new RequestTargetHostHC4(),
new RequestClientConnControl(),
new RequestUserAgentHC4(VersionInfoHC4.getUserAgent(
"Apache-HttpClient", "org.apache.http.client", getClass())));
this.requestExecutor = requestExecutor;
this.connManager = connManager;
this.reuseStrategy = reuseStrategy;
this.keepAliveStrategy = keepAliveStrategy;
}
示例9: InternalHttpClient
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
public InternalHttpClient(
final ClientExecChain execChain,
final HttpClientConnectionManager connManager,
final HttpRoutePlanner routePlanner,
final Lookup<CookieSpecProvider> cookieSpecRegistry,
final Lookup<AuthSchemeProvider> authSchemeRegistry,
final CookieStore cookieStore,
final CredentialsProvider credentialsProvider,
final RequestConfig defaultConfig,
final List<Closeable> closeables) {
super();
Args.notNull(execChain, "HTTP client exec chain");
Args.notNull(connManager, "HTTP connection manager");
Args.notNull(routePlanner, "HTTP route planner");
this.execChain = execChain;
this.connManager = connManager;
this.routePlanner = routePlanner;
this.cookieSpecRegistry = cookieSpecRegistry;
this.authSchemeRegistry = authSchemeRegistry;
this.cookieStore = cookieStore;
this.credentialsProvider = credentialsProvider;
this.defaultConfig = defaultConfig;
this.closeables = closeables;
}
示例10: performLogoutOnServiceProviders
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
public void performLogoutOnServiceProviders(String idpSessionId) {
List<String> serviceProviderLogoutUrls = idpConfig.getServiceProviderLogoutUrls();
asyncServiceLogoutExecutor.submit(() -> {
HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
HttpClient client = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
try {
for (String serviceProviderLogoutUrl : serviceProviderLogoutUrls) {
callLoggedOutServiceUrl(client, serviceProviderLogoutUrl, idpSessionId);
}
} catch (Throwable ex) {
log.error("Unable to perform logout on IDP services for session {}", idpSessionId, ex);
} finally {
connectionManager.shutdown();
}
});
}
示例11: MinimalClientExec
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
public MinimalClientExec(
final HttpRequestExecutor requestExecutor,
final HttpClientConnectionManager connManager,
final ConnectionReuseStrategy reuseStrategy,
final ConnectionKeepAliveStrategy keepAliveStrategy) {
Args.notNull(requestExecutor, "HTTP request executor");
Args.notNull(connManager, "Client connection manager");
Args.notNull(reuseStrategy, "Connection reuse strategy");
Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
this.httpProcessor = new ImmutableHttpProcessor(
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
new RequestUserAgent(VersionInfo.getUserAgent(
"Apache-HttpClient", "org.apache.http.client", getClass())));
this.requestExecutor = requestExecutor;
this.connManager = connManager;
this.reuseStrategy = reuseStrategy;
this.keepAliveStrategy = keepAliveStrategy;
}
示例12: createMainExec
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
/**
* Produces an instance of {@link ClientExecChain} to be used as a main exec.
* <p>
* Default implementation produces an instance of {@link MainClientExec}
* </p>
* <p>
* For internal use.
* </p>
*
* @since 4.4
*/
protected ClientExecChain createMainExec(
final HttpRequestExecutor requestExec,
final HttpClientConnectionManager connManager,
final ConnectionReuseStrategy reuseStrategy,
final ConnectionKeepAliveStrategy keepAliveStrategy,
final HttpProcessor proxyHttpProcessor,
final AuthenticationStrategy targetAuthStrategy,
final AuthenticationStrategy proxyAuthStrategy,
final UserTokenHandler userTokenHandler)
{
return new MainClientExec(
requestExec,
connManager,
reuseStrategy,
keepAliveStrategy,
proxyHttpProcessor,
targetAuthStrategy,
proxyAuthStrategy,
userTokenHandler);
}
示例13: testEvictExpiredAndIdle
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
@Test
public void testEvictExpiredAndIdle() throws Exception {
final HttpClientConnectionManager cm = Mockito.mock(HttpClientConnectionManager.class);
final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
500, TimeUnit.MILLISECONDS, 3, TimeUnit.SECONDS);
connectionEvictor.start();
Thread.sleep(1000);
Mockito.verify(cm, Mockito.atLeast(1)).closeExpiredConnections();
Mockito.verify(cm, Mockito.atLeast(1)).closeIdleConnections(3000, TimeUnit.MILLISECONDS);
Assert.assertTrue(connectionEvictor.isRunning());
connectionEvictor.shutdown();
connectionEvictor.awaitTermination(1, TimeUnit.SECONDS);
Assert.assertFalse(connectionEvictor.isRunning());
}
示例14: testEvictExpiredOnly
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
@Test
public void testEvictExpiredOnly() throws Exception {
final HttpClientConnectionManager cm = Mockito.mock(HttpClientConnectionManager.class);
final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
500, TimeUnit.MILLISECONDS, 0, TimeUnit.SECONDS);
connectionEvictor.start();
Thread.sleep(1000);
Mockito.verify(cm, Mockito.atLeast(1)).closeExpiredConnections();
Mockito.verify(cm, Mockito.never()).closeIdleConnections(Mockito.anyLong(), Mockito.<TimeUnit>any());
Assert.assertTrue(connectionEvictor.isRunning());
connectionEvictor.shutdown();
connectionEvictor.awaitTermination(1, TimeUnit.SECONDS);
Assert.assertFalse(connectionEvictor.isRunning());
}
示例15: setup
import org.apache.http.conn.HttpClientConnectionManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
execChain = Mockito.mock(ClientExecChain.class);
connManager = Mockito.mock(HttpClientConnectionManager.class);
routePlanner = Mockito.mock(HttpRoutePlanner.class);
cookieSpecRegistry = Mockito.mock(Lookup.class);
authSchemeRegistry = Mockito.mock(Lookup.class);
cookieStore = Mockito.mock(CookieStore.class);
credentialsProvider = Mockito.mock(CredentialsProvider.class);
defaultConfig = RequestConfig.custom().build();
closeable1 = Mockito.mock(Closeable.class);
closeable2 = Mockito.mock(Closeable.class);
client = new InternalHttpClient(execChain, connManager, routePlanner,
cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider,
defaultConfig, Arrays.asList(closeable1, closeable2));
}