本文整理汇总了Java中org.apache.http.impl.nio.client.HttpAsyncClients.custom方法的典型用法代码示例。如果您正苦于以下问题:Java HttpAsyncClients.custom方法的具体用法?Java HttpAsyncClients.custom怎么用?Java HttpAsyncClients.custom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.nio.client.HttpAsyncClients
的用法示例。
在下文中一共展示了HttpAsyncClients.custom方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
/**
* Creates an asynchronous HTTP client configuration with default timeouts.
*
* @see #newHttpAsyncClient(boolean)
*/
protected static CloseableHttpAsyncClient newHttpAsyncClient(boolean useSSL) {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT).build();
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
if (useSSL) {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[]{new TrustAllX509Manager()}, new SecureRandom());
SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(context,
SSLIOSessionStrategy.getDefaultHostnameVerifier());
builder.setSSLStrategy(strategy);
} catch (Exception e) {
log.error("Failed initializing SSL context! Skipped.", e);
}
}
return builder.setDefaultRequestConfig(requestConfig).build();
}
示例2: getAsyncProxyHttpClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的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();
}
示例3: QueryExecutor
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
private QueryExecutor(String userAgent, ObjectMapper mapper, HttpHost proxy)
{
checkNotNull(userAgent, "userAgent is null");
checkNotNull(mapper, "mapper is null");
this.userAgent = userAgent;
this.mapper = mapper;
HttpClientBuilder builder = HttpClients.custom();
HttpAsyncClientBuilder asyncBuilder = HttpAsyncClients.custom();
if (proxy != null) {
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
builder.setRoutePlanner(routePlanner);
asyncBuilder.setRoutePlanner(routePlanner);
}
this.httpClient = asyncBuilder.build();
this.httpClient.start();
}
示例4: createHttpClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
private CloseableHttpAsyncClient createHttpClient() {
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setConnectionRequestTimeout(TIMEOUT_CONNECTION_REQUEST);
requestConfigBuilder.setConnectTimeout(TIMEOUT_CONNECT);
requestConfigBuilder.setSocketTimeout(TIMEOUT_SOCKET);
if (this.mProxyHost != null) {
requestConfigBuilder.setProxy(this.mProxyHost);
}
final HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
final RequestConfig requestConfig = requestConfigBuilder.build();
clientBuilder.setDefaultRequestConfig(requestConfig);
if (this.mProxyHost != null && !StringUtils.isEmpty(this.mProxyUsername)) {
final AuthScope authScope = new AuthScope(this.mProxyHost);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
final Credentials credentials = new UsernamePasswordCredentials(this.mProxyUsername, this.mProxyPassword);
credentialsProvider.setCredentials(authScope, credentials);
clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
return clientBuilder.build();
}
示例5: create
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
public static CloseableHttpAsyncClient create(RequestConfig requestConfig) {
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
builder.setConnectionManager(connManager)
.setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(credentialsProvider);
if (null != requestConfig) {
return builder.setDefaultRequestConfig(requestConfig).build();
} else {
return builder.setDefaultRequestConfig(defaultRequestConfig)
.build();
}
}
示例6: createHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的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();
}
示例7: build
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
/**
* Builds the RestClient.
*
* @return
*/
public RestClient build() {
AsyncRestClient client = new AsyncRestClient();
client.setUriPrefix(uriPrefix);
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
if (requestConfig != null) {
builder.setDefaultRequestConfig(requestConfig);
}
if (userAgentName != null) {
builder.setUserAgent(userAgentName);
}
if (sslContext != null) {
builder.setSSLContext(sslContext);
}
if (connectionReuseStrategy != null) {
builder.setConnectionReuseStrategy(connectionReuseStrategy);
}
if (defaultHeaders != null) {
builder.setDefaultHeaders(Arrays.asList(defaultHeaders));
}
CloseableHttpAsyncClient httpClient = builder.build();
httpClient.start();
client.setHttpClient(httpClient, false);
client.setSerDe(serDe);
return client;
}
示例8: createHttpAsyncClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的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();
}
示例9: createPoolingHttpClient
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的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;
}
示例10: createCommon
import org.apache.http.impl.nio.client.HttpAsyncClients; //导入方法依赖的package包/类
/**
* 创建通用的AsyncHttpClient实例
* <p>Function: createCommon</p>
* <p>Description: </p>
* @author [email protected]
* @date 2016年12月13日 下午2:20:45
* @version 1.0
* @return
*/
public static AsyncHttpClient createCommon(){
HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom();
httpAsyncClientBuilder.setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
return new AsyncHttpClient(httpAsyncClientBuilder.build(),true);
}