当前位置: 首页>>代码示例>>Java>>正文


Java HttpAsyncClients.custom方法代码示例

本文整理汇总了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();
}
 
开发者ID:vexelon-dot-net,项目名称:currencybg.server,代码行数:28,代码来源:AbstractSource.java

示例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();
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:17,代码来源:HttpProxyClient.java

示例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();
}
 
开发者ID:prestodb,项目名称:presto-jdbc-java6,代码行数:21,代码来源:QueryExecutor.java

示例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();
    }
 
开发者ID:mwaylabs,项目名称:relution-jenkins-plugin,代码行数:27,代码来源:RequestManager.java

示例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();
	}
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:14,代码来源:AsynHttpPool.java

示例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();
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-java-sdk,代码行数:34,代码来源:HttpFactory.java

示例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;
}
 
开发者ID:Kixeye,项目名称:relax,代码行数:35,代码来源:RestClients.java

示例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();
}
 
开发者ID:JobHive,项目名称:saki-monkey,代码行数:45,代码来源:MandrillAsyncClient.java

示例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;
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:45,代码来源:HttpClientFactory.java

示例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);
}
 
开发者ID:thankjava,项目名称:java-toolkit,代码行数:15,代码来源:AsyncHttpClientBuilder.java


注:本文中的org.apache.http.impl.nio.client.HttpAsyncClients.custom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。