本文整理汇总了Java中org.apache.http.config.RegistryBuilder.create方法的典型用法代码示例。如果您正苦于以下问题:Java RegistryBuilder.create方法的具体用法?Java RegistryBuilder.create怎么用?Java RegistryBuilder.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.config.RegistryBuilder
的用法示例。
在下文中一共展示了RegistryBuilder.create方法的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: createConnection
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
/**
* Creates a new configured instance of {@link CloseableHttpClient} based
* on the factory's configuration.
*
* @return new connection object instance
*/
public CloseableHttpClient createConnection() {
final ConnectionSocketFactory socketFactory =
new CloudApiSSLConnectionSocketFactory(config);
final RegistryBuilder<ConnectionSocketFactory> registryBuilder =
RegistryBuilder.create();
final Registry<ConnectionSocketFactory> socketFactoryRegistry = registryBuilder
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", socketFactory)
.build();
final PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager(socketFactoryRegistry,
DNS_RESOLVER);
httpClientBuilder.setConnectionManager(connectionManager);
return httpClientBuilder.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: KerberosHttpClient
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
private KerberosHttpClient(String user, String password, String domain, String kdc) {
try {
File krb5Config = createKrb5Configuration(domain, kdc);
File loginConfig = createLoginConfiguration();
System.setProperty("java.security.auth.login.config", loginConfig.toURI().toString());
System.setProperty("java.security.krb5.conf", krb5Config.toURI().toString());
System.setProperty("sun.security.krb5.debug", "false");
//Change this property to true, if you want debug output.
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
RegistryBuilder<AuthSchemeProvider> registryBuilder = RegistryBuilder.create();
String id = AuthSchemes.SPNEGO;
SPNegoSchemeFactory schemeFactory = new SPNegoSchemeFactory(SKIP_PORT_AT_KERBEROS_DATABASE_LOOKUP);
Lookup<AuthSchemeProvider> authSchemeRegistry = registryBuilder.register(id, schemeFactory).build();
client = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry)
.setConnectionManager(createConnectionManager()).build();
httpContext = getHttpContext();
loginContext = getLoginContext(user, password);
//without it, authentication will be failed.
final Subject subject = loginContext.getSubject();
final HttpGet get = new HttpGet(KerberosBpmClient.this.rootUri);
Subject.doAs(subject, this.privilegedExecute(get, httpContext));
} catch (Exception e) {
logger.error("Can't create Kerberos client!");
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例6: httpClientFactory
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
protected CloseableHttpClient httpClientFactory() throws CannotInitializeDataAdapterException {
try {
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(
createSslCustomContext(),
null,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
RegistryBuilder<AuthSchemeProvider> schemeProviderBuilder = RegistryBuilder.create();
schemeProviderBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1, null),
new Credentials() {
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public String getPassword() {
return null;
}
});
return HttpClients.custom()
.setDefaultAuthSchemeRegistry(schemeProviderBuilder.build())
.setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(csf)
.build();
} catch (IOException | UnrecoverableKeyException | CertificateException | NoSuchAlgorithmException | KeyStoreException | NoSuchProviderException | KeyManagementException e) {
throw new CannotInitializeDataAdapterException("Could not initialize adapter to source '" + this.getSourceName() + "': " + e.getMessage(), e);
}
}
示例7: main
import org.apache.http.config.RegistryBuilder; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.setProperty("java.security.auth.login.config", ClientKerberosAuthentication.class.getResource("/jaas_login.conf").toExternalForm());
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
String targetUrl;
if (args.length < 1) {
throw new IllegalArgumentException("Please specify a target URL");
}
targetUrl = args[0];
/* ***********************************************************************************************/
RegistryBuilder<AuthSchemeProvider> schemeProviderBuilder = RegistryBuilder.create();
schemeProviderBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new Credentials() {
@Override
public Principal getUserPrincipal() {
System.out.print("Get principal!");
return null;
}
@Override
public String getPassword() {
System.out.print("Get pwd!");
return null;
}
});
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(schemeProviderBuilder.build())
.setDefaultCredentialsProvider(credsProvider)
.build();
doGet(httpClient, targetUrl);
httpClient.close();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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;
}
示例12: 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();
}
示例13: 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;
}
示例14: 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;
}
示例15: 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();
}
}