本文整理汇总了Java中org.apache.http.config.RegistryBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java RegistryBuilder.build方法的具体用法?Java RegistryBuilder.build怎么用?Java RegistryBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.config.RegistryBuilder
的用法示例。
在下文中一共展示了RegistryBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.apache.http.config.RegistryBuilder; //导入方法依赖的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: setUsernamePassword
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
@Override public void setUsernamePassword(AuthenticationType authType, String username,
String password) {
this.credentials = new UsernamePasswordCredentials(
Objects.requireNonNull(username), Objects.requireNonNull(password));
this.credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
RegistryBuilder<AuthSchemeProvider> authRegistryBuilder = RegistryBuilder.create();
switch (authType) {
case BASIC:
authRegistryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory());
break;
case DIGEST:
authRegistryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
break;
default:
throw new IllegalArgumentException("Unsupported authentiation type: " + authType);
}
this.authRegistry = authRegistryBuilder.build();
}
示例3: init
import org.apache.http.config.RegistryBuilder; //导入方法依赖的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();
}
示例4: createConnectionRegistry
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
protected Registry<ConnectionSocketFactory> createConnectionRegistry(X509HostnameVerifier x509HostnameVerifier, SSLContextParameters sslContextParams)
throws GeneralSecurityException, IOException {
// create the default connection registry to use
RegistryBuilder<ConnectionSocketFactory> builder = RegistryBuilder.<ConnectionSocketFactory>create();
builder.register("http", PlainConnectionSocketFactory.getSocketFactory());
builder.register("http4", PlainConnectionSocketFactory.getSocketFactory());
if (sslContextParams != null) {
builder.register("https", new SSLConnectionSocketFactory(sslContextParams.createSSLContext(getCamelContext()), x509HostnameVerifier));
builder.register("https4", new SSLConnectionSocketFactory(sslContextParams.createSSLContext(getCamelContext()), x509HostnameVerifier));
} else {
builder.register("https4", new SSLConnectionSocketFactory(SSLContexts.createDefault(), x509HostnameVerifier));
builder.register("https", new SSLConnectionSocketFactory(SSLContexts.createDefault(), x509HostnameVerifier));
}
return builder.build();
}
示例5: getSchemeRegistry
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
public static Registry<ConnectionSocketFactory> getSchemeRegistry(final DockerCertificates dc) {
final SSLConnectionSocketFactory https;
if (dc == null) {
https = SSLConnectionSocketFactory.getSocketFactory();
} else {
https = new SSLConnectionSocketFactory(dc.sslContext(),
dc.hostnameVerifier());
}
final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
.<ConnectionSocketFactory>create()
.register("https", https)
.register("http",
PlainConnectionSocketFactory.getSocketFactory());
return registryBuilder.build();
}
示例6: YouTrackClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
public YouTrackClient(String host, String keyStoreType, String keyStorePath, String keyStorePassword, String keyPassword,
String trustStoreType, String trustStorePath, String trustStorePassword) {
this.host = host;
CookieStore cookieStore = new BasicCookieStore();
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SOCKET_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
LayeredConnectionSocketFactory sslFactory;
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory());
if (host.contains("https://")) {
try {
sslFactory = initSslContext(keyStoreType, keyStorePath, keyStorePassword, keyPassword, trustStoreType, trustStorePath, trustStorePassword);
registryBuilder.register("https", sslFactory);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
Registry<ConnectionSocketFactory> registry = registryBuilder.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(MAX_SIMULTANEOUS_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(MAX_SIMULTANEOUS_CONNECTIONS);
client = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.build();
}
示例7: RiscossRESTClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
public RiscossRESTClient(String base_addr) {
this.addr = base_addr;
RegistryBuilder<ConnectionSocketFactory> connRegistryBuilder = RegistryBuilder.create();
connRegistryBuilder.register("http", PlainConnectionSocketFactory.INSTANCE);
try { // Fixing: https://code.google.com/p/crawler4j/issues/detail?id=174
// By always trusting the ssl certificate
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(final X509Certificate[] chain, String authType) {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
connRegistryBuilder.register("https", sslsf);
} catch (KeyManagementException | KeyStoreException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
Registry<ConnectionSocketFactory> connRegistry = connRegistryBuilder.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(connRegistry);
connectionManager.setMaxTotal(5);
connectionManager.setDefaultMaxPerRoute(5);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setDefaultRequestConfig(requestConfig);
clientBuilder.setConnectionManager(connectionManager);
clientBuilder.setUserAgent("Cognitio");
client = clientBuilder.build();
}
示例8: HttpModelControllerClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
HttpModelControllerClient(String host, int port, String username, String password, int timeoutMillis,
SslOptions ssl) throws IOException {
// timeout configuration
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (timeoutMillis != NO_TIMEOUT) {
requestConfigBuilder
.setConnectTimeout(timeoutMillis)
.setSocketTimeout(timeoutMillis);
}
requestConfig = requestConfigBuilder.build();
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create();
if (ssl != null) {
url = "https://" + host + ":" + port + "/management";
SSLConnectionSocketFactory sslConnectionSocketFactory;
if (ssl.hostnameVerification) {
sslConnectionSocketFactory = new SSLConnectionSocketFactory(ssl.createSslContext());
} else {
sslConnectionSocketFactory = new SSLConnectionSocketFactory(
ssl.createSslContext(), NoopHostnameVerifier.INSTANCE);
}
registryBuilder.register("https", sslConnectionSocketFactory);
} else {
url = "http://" + host + ":" + port + "/management";
registryBuilder.register("http", PlainConnectionSocketFactory.getSocketFactory());
}
registry = registryBuilder.build();
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (username != null && password != null) {
credentialsProvider.setCredentials(
new AuthScope(host, port, getManagementRealm(url), AuthSchemes.DIGEST),
new UsernamePasswordCredentials(username, password));
}
client = HttpClients.custom()
.setConnectionManager(new PoolingHttpClientConnectionManager(registry))
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultRequestConfig(requestConfig)
.build();
}
示例9: getSchemeRegistry
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
private org.apache.http.config.Registry<ConnectionSocketFactory> getSchemeRegistry(final URI originalUri,
SSLContext sslContext) {
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
registryBuilder.register("http", PlainConnectionSocketFactory.getSocketFactory());
if (sslContext != null) {
registryBuilder.register("https", new SSLConnectionSocketFactory(sslContext));
}
registryBuilder.register("unix", new UnixConnectionSocketFactory(originalUri));
return registryBuilder.build();
}
示例10: createHttpClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
private HttpClient createHttpClient(ConnectionConfig config) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(config.getConnectionTimeoutMs())
.setSocketTimeout(config.getSocketTimeoutMs())
.build();
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
registryBuilder.register("http", new PlainConnectionSocketFactory());
if (config.isHttpsEnabled()) {
SSLContext sslContext = SSLContexts.createSystemDefault();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslContext,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
registryBuilder.register("https", sslsf);
}
connectionManager = new PoolingHttpClientConnectionManager(registryBuilder.build());
connectionManager.setDefaultMaxPerRoute(config.getMaxConnection());
connectionManager.setMaxTotal(config.getMaxConnection());
HttpClient httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false))
.build();
return httpClient;
}
示例11: setupSchemeRegistry
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
private static Registry<ConnectionSocketFactory> setupSchemeRegistry(SSLContext sslContext) {
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
registryBuilder.register("http", PlainConnectionSocketFactory.getSocketFactory());
if (sslContext != null) {
registryBuilder.register("https", new SSLConnectionSocketFactory(sslContext));
}
return registryBuilder.build();
}
示例12: getConnectionManager
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
public static HttpClientConnectionManager getConnectionManager() {
// ConnectionSocketFactory plainsf = null;
LayeredConnectionSocketFactory sslsf = null;
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
registryBuilder.register("http", plainsf);
try {
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
return true;
}
}).build();
HostnameVerifier allowAllHostnameVerifier = NoopHostnameVerifier.INSTANCE;
sslsf = new SSLConnectionSocketFactory(sslcontext, allowAllHostnameVerifier);
registryBuilder.register("https", sslsf);
} catch (Throwable e) {
logger.error("https ssl init failed", e);
}
Registry<ConnectionSocketFactory> r = registryBuilder.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(r);
connManager.setMaxTotal(100);// 连接池最大并发连接数
connManager.setDefaultMaxPerRoute(100);// 单路由最大并发数
return connManager;
}
示例13: getClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
/**
* Get client.
*
* @return the client
*/
private synchronized CloseableHttpClient getClient() {
if (client == null) {
RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder.setConnectTimeout(connectionTimeout);
ConnectionConfig.Builder connBuilder = ConnectionConfig.custom();
connBuilder.setCharset(Charset.forName(getContentCharset()));
// Create and initialize scheme registry
RegistryBuilder<ConnectionSocketFactory> builder = RegistryBuilder.create();
builder.register("http", getPlainFactory());
builder.register("https", getSslFactory());
Registry<ConnectionSocketFactory> registry = builder.build();
HttpClientConnectionManager hccm = createClientConnectionManager(registry);
HttpClientBuilder clientBuilder = HttpClients.custom();
clientBuilder.setDefaultRequestConfig(requestBuilder.build());
clientBuilder.setDefaultConnectionConfig(connBuilder.build());
clientBuilder.setConnectionManager(hccm);
client = clientBuilder.build();
}
return client;
}
示例14: setClientBuilder
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
@SneakyThrows
private void setClientBuilder() {
try {
KeyManager[] keyStoreManagers = null;
if (!parameters.getKeystore().isEmpty()) {
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("jks");
keyStore.load(new FileInputStream(parameters.getKeystore()), parameters.getKeystorePassword().toCharArray());
kmf.init(keyStore, parameters.getKeystorePassword().toCharArray());
keyStoreManagers = kmf.getKeyManagers();
}
TrustManager[] trustStoreManagers = null;
if (!parameters.getTruststore().isEmpty()) {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance("jks");
trustStore.load(new FileInputStream(parameters.getTruststore()), parameters.getTruststorePassword().toCharArray());
tmf.init(trustStore);
trustStoreManagers = tmf.getTrustManagers();
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyStoreManagers, trustStoreManagers, null);
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
RegistryBuilder<ConnectionSocketFactory> rb = RegistryBuilder.<ConnectionSocketFactory> create();
rb.register("https", scsf);
rb.register("http", PlainConnectionSocketFactory.getSocketFactory());
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(rb.build());
connManager.setMaxTotal(parameters.getParallelism());
connManager.setDefaultMaxPerRoute(parameters.getParallelism());
clientBuilder.setConnectionManager(connManager);
RequestConfig.Builder configBuilder = RequestConfig.custom();
configBuilder = configBuilder.setSocketTimeout(parameters.getSocketTimeout());
configBuilder = configBuilder.setConnectTimeout(parameters.getConnectTimeout());
clientBuilder.setDefaultRequestConfig(configBuilder.build());
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: getClientBuilder
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
@SneakyThrows
private HttpClientBuilder getClientBuilder() {
RegistryBuilder<ConnectionSocketFactory> csf = RegistryBuilder.<ConnectionSocketFactory> create();
KeyManager[] keyStoreManagers = null;
if (cmd.get("keystore") != null) {
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("jks");
// System.out.printf("keystore=%s
// keystorePassword=%s%n",map.get("keystore"),
// map.get("keystorePassword"));
keyStore.load(new FileInputStream(cmd.get("keystore")), null);
kmf.init(keyStore, cmd.get("keystorePassword").toCharArray());
keyStoreManagers = kmf.getKeyManagers();
}
TrustManager[] trustStoreManagers = null;
if (cmd.get("truststore") != null) {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance("jks");
// System.out.printf("truststore=%s
// truststorePassword=%s%n",map.get("truststore"),
// map.get("truststorePassword"));
trustStore.load(new FileInputStream(cmd.get("truststore")), null);
tmf.init(trustStore);
trustStoreManagers = tmf.getTrustManagers();
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyStoreManagers, trustStoreManagers, null);
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
csf.register("https", scsf);
csf.register("http", PlainConnectionSocketFactory.getSocketFactory());
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(csf.build());
int maxPerRoute = 2 * Integer.valueOf(cmd.getOrDefault("pa", "" + Runtime.getRuntime().availableProcessors()));
connManager.setDefaultMaxPerRoute(maxPerRoute);
connManager.setValidateAfterInactivity(-1);
// connManager.
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connManager);
return builder;
}