當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientBuilder.setSSLHostnameVerifier方法代碼示例

本文整理匯總了Java中org.apache.http.impl.client.HttpClientBuilder.setSSLHostnameVerifier方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientBuilder.setSSLHostnameVerifier方法的具體用法?Java HttpClientBuilder.setSSLHostnameVerifier怎麽用?Java HttpClientBuilder.setSSLHostnameVerifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.setSSLHostnameVerifier方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: get

import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
public static CloseableHttpClient get(SSLContext ssl, CookieStore cookieStore, boolean hostVerificationEnabled) {
    RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();

    HttpClientBuilder builder = HttpClients.custom().setSSLContext(ssl).setDefaultCookieStore(cookieStore)
            .setDefaultRequestConfig(defaultRequestConfig);
    if (hostVerificationEnabled) {
        builder.setSSLHostnameVerifier(new DefaultHostnameVerifier());
    } else {
        builder.setSSLHostnameVerifier(new NoopHostnameVerifier());
    }
    return builder.build();
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:13,代碼來源:HttpClient.java

示例4: 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

示例5: 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.setSSLHostnameVerifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。