本文整理汇总了Java中org.apache.http.conn.socket.ConnectionSocketFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionSocketFactory类的具体用法?Java ConnectionSocketFactory怎么用?Java ConnectionSocketFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionSocketFactory类属于org.apache.http.conn.socket包,在下文中一共展示了ConnectionSocketFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的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: getConnctionManager
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public static PoolingHttpClientConnectionManager getConnctionManager(){
Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
try {
SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
new TrustAllHostNameVerifier());
socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory> create()
.register("http", new PlainConnectionSocketFactory())
.register("https", trustSelfSignedSocketFactory)
.build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
Data.logger.warn("", e);
}
PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ?
new PoolingHttpClientConnectionManager(socketFactoryRegistry):
new PoolingHttpClientConnectionManager();
// twitter specific options
cm.setMaxTotal(2000);
cm.setDefaultMaxPerRoute(200);
return cm;
}
示例3: upgrade
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public void upgrade(
final ManagedHttpClientConnection conn,
final HttpHost host,
final HttpContext context) throws IOException {
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
if (sf == null) {
throw new UnsupportedSchemeException(host.getSchemeName() +
" protocol is not supported");
}
if (!(sf instanceof LayeredConnectionSocketFactory)) {
throw new UnsupportedSchemeException(host.getSchemeName() +
" protocol does not support connection upgrade");
}
final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
Socket sock = conn.getSocket();
final int port = this.schemePortResolver.resolve(host);
sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
conn.bind(sock);
}
示例4: createConnectionManager
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的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;
}
示例5: OAuthHttpClient
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public OAuthHttpClient(int maxConnection, int connectTimeout, int socketTimeout) {
PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build());
// set max connection
connectionManager.setMaxTotal(maxConnection);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.build();
httpClient = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
}
示例6: getSslFactoryRegistry
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
private static Registry<ConnectionSocketFactory> getSslFactoryRegistry(String certPath) throws IOException {
try {
KeyStore keyStore = KeyStoreUtils.createDockerKeyStore(certPath);
SSLContext sslContext =
SSLContexts.custom()
.useTLS()
.loadKeyMaterial(keyStore, "docker".toCharArray())
.loadTrustMaterial(keyStore)
.build();
SSLConnectionSocketFactory sslsf =
new SSLConnectionSocketFactory(sslContext);
return RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslsf).build();
} catch (GeneralSecurityException e) {
throw new IOException(e);
}
}
示例7: init
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public void init() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
/* 配置同时支持 HTTP 和 HTPPS */
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
/* 初始化连接管理器 */
poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolConnManager.setMaxTotal(maxTotal);
poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
httpClient = getConnection();
log.info("HttpConnectionManager初始化完成...");
} catch (Exception e) {
log.error("error", e);
}
}
示例8: httpsGet
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public static String httpsGet(String getUrl, String defaultCharset, Map<String, String> headerParas)
throws KeyManagementException, NoSuchAlgorithmException {
// 采用绕过验证的方式处理https请求
SSLContext sslcontext = createIgnoreVerifySSL();
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager);
// 创建自定义的httpclient对象
CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager).build();
return getInner(getUrl, defaultCharset, headerParas, httpclient);
}
示例9: initPoolingHttpClientManager
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
private void initPoolingHttpClientManager () {
final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.register("http", PlainConnectionSocketFactory.getSocketFactory()).build();
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(MAX_CONNECTION);
connectionManager.setDefaultMaxPerRoute(MAX_CONNECTION_PER_ROUTE);
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)
.setConnectionRequestTimeout(CONNECTION_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT);
final RequestConfig requestConfig = requestConfigBuilder.build();
HashSet<Header> defaultHeaders = new HashSet<Header>();
defaultHeaders.add(new BasicHeader(HttpHeaders.PRAGMA, "no-cache"));
defaultHeaders.add(new BasicHeader(HttpHeaders.CACHE_CONTROL, "no-cache"));
final HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultHeaders(defaultHeaders).disableAuthCaching().disableContentCompression();
this.httpClient = httpClientBuilder.setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
}
示例10: getCustomClient
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
/**
* custom http client for server with SSL errors
*
* @return
*/
public final CloseableHttpClient getCustomClient() {
try {
HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
(TrustStrategy) (X509Certificate[] arg0, String arg1) -> true).build();
builder.setSSLContext(sslContext);
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build();
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
builder.setConnectionManager(connMgr);
return builder.build();
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
return getSystemClient();
}
示例11: create
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的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;
}
示例12: create
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的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;
}
示例13: createSocketFactoryRegistry
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
private Registry<ConnectionSocketFactory> createSocketFactoryRegistry(ConnectionSocketFactory sslSocketFactory) {
/*
* If SSL cert checking for endpoints has been explicitly disabled,
* register a new scheme for HTTPS that won't cause self-signed certs to
* error out.
*/
if (SDKGlobalConfiguration.isCertCheckingDisabled()) {
if (LOG.isWarnEnabled()) {
LOG.warn("SSL Certificate checking for endpoints has been " +
"explicitly disabled.");
}
sslSocketFactory = new TrustingSocketFactory();
}
return RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build();
}
示例14: init
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
private void init() {
final URI originalUri = URI.create(DEFAULT_UNIX_ENDPOINT);
sanitizeUri = UnixFactory.sanitizeUri(originalUri);
final RegistryBuilder<ConnectionSocketFactory> registryBuilder =
RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("unix", new UnixFactory(originalUri));
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(registryBuilder.build());
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout((int) SECONDS.toMillis(5))
.setConnectTimeout((int) SECONDS.toMillis(5))
.setSocketTimeout((int) SECONDS.toMillis(30))
.build();
final ClientConfig config = new ClientConfig()
.connectorProvider(new ApacheConnectorProvider())
.property(ApacheClientProperties.CONNECTION_MANAGER, cm)
.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
client = ClientBuilder.newBuilder().withConfig(config).build();
}
示例15: createHttpClient
import org.apache.http.conn.socket.ConnectionSocketFactory; //导入依赖的package包/类
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
s_logger.info("Creating new HTTP connection pool and client");
final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
final BasicCookieStore cookieStore = new BasicCookieStore();
final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
final RequestConfig requestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setMaxRedirects(maxRedirects)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
.setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
.build();
return HttpClientBuilder.create()
.setConnectionManager(connManager)
.setRedirectStrategy(new LaxRedirectStrategy())
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.setRetryHandler(new StandardHttpRequestRetryHandler())
.build();
}