本文整理匯總了Java中org.apache.http.impl.nio.client.HttpAsyncClientBuilder.setConnectionManager方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpAsyncClientBuilder.setConnectionManager方法的具體用法?Java HttpAsyncClientBuilder.setConnectionManager怎麽用?Java HttpAsyncClientBuilder.setConnectionManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.nio.client.HttpAsyncClientBuilder
的用法示例。
在下文中一共展示了HttpAsyncClientBuilder.setConnectionManager方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAsyncProxyHttpClient
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入方法依賴的package包/類
private CloseableHttpAsyncClient getAsyncProxyHttpClient(URI proxyUri) {
LOG.info("Creating async proxy http client");
PoolingNHttpClientConnectionManager cm = getAsyncConnectionManager();
HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort());
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
if (cm != null) {
clientBuilder = clientBuilder.setConnectionManager(cm);
}
if (proxy != null) {
clientBuilder = clientBuilder.setProxy(proxy);
}
clientBuilder = setRedirects(clientBuilder);
return clientBuilder.build();
}
示例2: ApacheHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入方法依賴的package包/類
public ApacheHttpAsyncClient(HttpAsyncClientBuilder builder, Config config, SharedResourcesBroker<GobblinScopeTypes> broker) {
super (broker, HttpUtils.createApacheHttpClientLimiterKey(config));
config = config.withFallback(FALLBACK);
RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT)
.setSocketTimeout(config.getInt(REQUEST_TIME_OUT_MS_KEY))
.setConnectTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY))
.setConnectionRequestTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY))
.build();
try {
builder.disableCookieManagement().useSystemProperties().setDefaultRequestConfig(requestConfig);
builder.setConnectionManager(getNHttpConnManager(config));
client = builder.build();
client.start();
} catch (IOException e) {
throw new RuntimeException("ApacheHttpAsyncClient cannot be initialized");
}
}
示例3: createHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入方法依賴的package包/類
public CloseableHttpAsyncClient createHttpAsyncClient(
ClientConfiguration config, PoolingNHttpClientConnectionManager cm) {
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClients.custom();
httpClientBuilder.setConnectionManager(cm);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(config.getConnectionTimeoutInMillisecond())
.setSocketTimeout(config.getSocketTimeoutInMillisecond()).build();
httpClientBuilder.setDefaultRequestConfig(requestConfig);
httpClientBuilder.setUserAgent(config.getUserAgent());
httpClientBuilder.disableCookieManagement();
String proxyHost = config.getProxyHost();
int proxyPort = config.getProxyPort();
if (proxyHost != null) {
if (proxyPort <= 0) {
throw new ClientException("The proxy port is invalid. Please check your configuration.");
}
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
httpClientBuilder.setProxy(proxy);
String proxyUsername = config.getProxyUsername();
String proxyPassword = config.getProxyPassword();
if (proxyUsername != null && proxyPassword != null) {
String proxyDomain = config.getProxyDomain();
String proxyWorkstation = config.getProxyWorkstation();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(proxyHost, proxyPort), new NTCredentials(
proxyUsername, proxyPassword, proxyWorkstation,
proxyDomain));
httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
}
}
return httpClientBuilder.build();
}
示例4: createHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入方法依賴的package包/類
/**
* Factory method for Apache HttpAsyncClient
*
* @return
*/
protected CloseableHttpAsyncClient createHttpAsyncClient() {
log.info("Creating HttpAsyncClient");
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
clientBuilder.setSSLStrategy(createSSLIOSessionStrategy());
/*
* defaultMaxPerRoute and maxTotal will be overridden by connection manager
* if it is set.
*/
ConnectionSettings connSettings = createConnectionSettings();
clientBuilder.setConnectionManagerShared(connSettings.shared);
clientBuilder.setMaxConnPerRoute(connSettings.defaultMaxPerRoute);
clientBuilder.setMaxConnTotal(connSettings.maxTotal);
NHttpClientConnectionManager connectionManager = createConnectionManager();
if(connectionManager != null){
log.info("Connection manager is set");
clientBuilder.setConnectionManager(connectionManager);
}
HttpHost proxy = detectHttpProxy();
if (proxy != null) {
clientBuilder.setProxy(proxy);
CredentialsProvider credsProvider = createDefaultCredentialsProvider(
proxy.getHostName(), proxy.getPort());
if (credsProvider != null) {
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
}
String userAgent = getUserAgent();
log.debug("User-Agent: {}", userAgent);
clientBuilder.setUserAgent(userAgent);
clientBuilder.setDefaultRequestConfig(createDefaultRequestConfig());
return clientBuilder.build();
}
示例5: createPoolingHttpClient
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入方法依賴的package包/類
private static CloseableHttpAsyncClient createPoolingHttpClient(HiTSDBConfig config,PoolingNHttpClientConnectionManager cm,SemaphoreManager semaphoreManager) throws HttpClientInitException {
int httpConnectionPool = config.getHttpConnectionPool();
int httpConnectionLiveTime = config.getHttpConnectionLiveTime();
int httpKeepaliveTime = config.getHttpKeepaliveTime();
RequestConfig requestConfig = initRequestConfig(config);
if (httpConnectionPool > 0) {
cm.setMaxTotal(httpConnectionPool);
cm.setDefaultMaxPerRoute(httpConnectionPool);
cm.closeExpiredConnections();
}
HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom();
// 設置連接管理器
httpAsyncClientBuilder.setConnectionManager(cm);
// 設置RequestConfig
if (requestConfig != null) {
httpAsyncClientBuilder.setDefaultRequestConfig(requestConfig);
}
// 設置Keepalive
if (httpKeepaliveTime > 0) {
HiTSDBConnectionKeepAliveStrategy hiTSDBConnectionKeepAliveStrategy = new HiTSDBConnectionKeepAliveStrategy(httpConnectionLiveTime);
httpAsyncClientBuilder.setKeepAliveStrategy(hiTSDBConnectionKeepAliveStrategy);
} else if (httpKeepaliveTime == 0) {
HiTSDBConnectionReuseStrategy hiTSDBConnectionReuseStrategy = new HiTSDBConnectionReuseStrategy();
httpAsyncClientBuilder.setConnectionReuseStrategy(hiTSDBConnectionReuseStrategy);
}
// 設置連接自動關閉
if(httpConnectionLiveTime > 0) {
HiTSDBHttpAsyncCallbackExecutor httpAsyncCallbackExecutor = new HiTSDBHttpAsyncCallbackExecutor(httpConnectionLiveTime);
httpAsyncClientBuilder.setEventHandler(httpAsyncCallbackExecutor);
}
// 啟動定時調度
initFixedCycleCloseConnection(cm);
CloseableHttpAsyncClient client = httpAsyncClientBuilder.build();
return client;
}