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


Java HttpClientBuilder.setSSLContext方法代码示例

本文整理汇总了Java中org.apache.http.impl.client.HttpClientBuilder.setSSLContext方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientBuilder.setSSLContext方法的具体用法?Java HttpClientBuilder.setSSLContext怎么用?Java HttpClientBuilder.setSSLContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.setSSLContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBuilder

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@NotNull
static HttpClientBuilder getBuilder() {
  final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()).
    setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);

  final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance();
  final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL));
  final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress)proxies.get(0).address() : null;
  if (address != null) {
    builder.setProxy(new HttpHost(address.getHostName(), address.getPort()));
  }
  final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager();
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom());
    builder.setSSLContext(sslContext);
  }
  catch (NoSuchAlgorithmException | KeyManagementException e) {
    LOG.error(e.getMessage());
  }
  return builder;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:23,代码来源:EduStepicClient.java

示例2: createHttpClientBuilder

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
protected HttpClientBuilder createHttpClientBuilder(SiteConfig siteConfig) {
    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setConnectionTimeToLive(siteConfig.getConnTimeToLiveMillis(), TimeUnit.MILLISECONDS);
    httpClientBuilder.setMaxConnPerRoute(siteConfig.getMaxConnPerRoute());
    httpClientBuilder.setMaxConnTotal(siteConfig.getMaxConnTotal());
    httpClientBuilder.setUserAgent(siteConfig.getUserAgent());

    httpClientBuilder.setRetryHandler(createHttpRequestRetryHandler());
    httpClientBuilder.setRedirectStrategy(createRedirectStrategy());
    httpClientBuilder.setSSLContext(createSSLContext());
    httpClientBuilder.setSSLHostnameVerifier(createSSLHostnameVerifier());

    httpClientBuilder.setDefaultConnectionConfig(createConnectionConfig(siteConfig));
    httpClientBuilder.setDefaultSocketConfig(createSocketConfig(siteConfig));
    httpClientBuilder.setDefaultCookieSpecRegistry(createCookieSpecRegistry());
    httpClientBuilder.setDefaultCookieStore(createCookieStore());

    return httpClientBuilder;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:21,代码来源:HttpClientFactory.java

示例3: getCustomClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的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();
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:26,代码来源:AbstractHttpClient.java

示例4: disableSslValidationOnHttpClientBuilder

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private HttpClientBuilder disableSslValidationOnHttpClientBuilder(HttpClientBuilder builder)
{
    SSLContext sslContext;
    try {
        sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build();
        builder.setSSLContext(sslContext);
        builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        throw new RuntimeException("Could not disable SSL on HttpClient builder.", e);
    }
    return builder;
}
 
开发者ID:coveo,项目名称:k8s-proxy,代码行数:13,代码来源:HttpClientConfiguration.java

示例5: prepareRestTemplate

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
/**
 * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND
 * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}.
 *
 * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed
 * certificates.
 *
 * @param restTemplate Must not be null
 * @param username Can be null
 * @param password Can be null
 * @param skipSslValidation Use with caution! If true certificate warnings will be ignored.
 */
public static void prepareRestTemplate(
		RestTemplate restTemplate,
		String username,
		String password,
		boolean skipSslValidation) {

	Assert.notNull(restTemplate, "The provided RestTemplate must not be null.");

	final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

	if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
		final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY,
				new UsernamePasswordCredentials(
						username,
						password));
		httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
	}

	if (skipSslValidation) {
		httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext());
		httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
	}

	final CloseableHttpClient httpClient = httpClientBuilder.build();
	final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
	restTemplate.setRequestFactory(requestFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:41,代码来源:HttpClientUtils.java

示例6: extend

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
public HttpClientBuilder extend(HttpClientBuilder httpClientBuilder, GerritAuthData authData) {
    HttpClientBuilder builder = super.extend(httpClientBuilder, authData);
    builder.setSSLContext(trustAnyX509Certificate);
    builder.setSSLHostnameVerifier(acceptAnyX509Hostname);
    return builder;
}
 
开发者ID:GerritForge,项目名称:gerrit-plugin,代码行数:8,代码来源:SSLNoVerifyCertificateManagerClientBuilderExtension.java


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