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


Java HttpClientBuilder.setSSLSocketFactory方法代码示例

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


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

示例1: execute1

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private static String execute1(HttpUriRequest httpUriRequest) throws Exception {
    CloseableHttpResponse closeableHttpResponse = null;
    httpUriRequest.addHeader("Connection", "close");
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().disableCookieManagement().disableConnectionState();

    try {
        httpClientBuilder.setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory());
    } catch (Exception var12) {
        LOGGER.error(httpUriRequest.toString(), var12);
    }

    CloseableHttpClient httpClient = httpClientBuilder.build();

    String var6;
    try {
        closeableHttpResponse = httpClient.execute(httpUriRequest);
        String response = EntityUtils.toString(closeableHttpResponse.getEntity(), CHARSET);
        var6 = response;
    } catch (Exception var10) {
        throw var10;
    } finally {
        CloseUtils.close(closeableHttpResponse);
        CloseUtils.close(httpClient);
    }
    return var6;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:27,代码来源:OpenClient.java

示例2: createHttpClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private HttpClient createHttpClient(Authentication auth, String verify, HttpHost target, Boolean postRedirects,
		String password, TrustStrategy keystoreTrustStrategy, HostnameVerifier keystoreHostnameVerifier,
		Proxy proxy) {
	Certificate certificate = new Certificate();
	Auth authHelper = new Auth();
	HttpClientBuilder httpClientBuilder = WinHttpClients.custom();
	Builder requestConfig = RequestConfig.custom();
	requestConfig.setCookieSpec(CookieSpecs.DEFAULT);

	logger.debug("Verify value: " + verify);
	logger.debug((new File(verify).getAbsolutePath()));

	if (new File(verify).exists()) {
		logger.debug("Loading custom keystore");
		httpClientBuilder.setSSLSocketFactory(
				certificate.allowAllCertificates(certificate.createCustomKeyStore(verify.toString(), password),
						password, keystoreTrustStrategy, keystoreHostnameVerifier));
	} else if (!Boolean.parseBoolean(verify.toString())) {
		logger.debug("Allowing all certificates");
		httpClientBuilder.setSSLSocketFactory(certificate.allowAllCertificates(null));
	}

	if (auth.isAuthenticable()) {
		httpClientBuilder.setDefaultCredentialsProvider(authHelper.getCredentialsProvider(auth, target));
	}

	if (proxy != null && proxy.isInUse()) {
		logger.debug("Enabling proxy");
		if (proxy.isAuthenticable()) {
			logger.debug("Setting proxy credentials");
			httpClientBuilder.setDefaultCredentialsProvider(
					authHelper.getCredentialsProvider(proxy.getAuth(), proxy.getHttpHost()));
		}
		requestConfig.setProxy(proxy.getHttpHost());
	}

	if (postRedirects) {
		httpClientBuilder.setRedirectStrategy(new CustomRedirectStrategy());
	}
	httpClientBuilder.setDefaultRequestConfig(requestConfig.build());

	return httpClientBuilder.build();
}
 
开发者ID:Hi-Fi,项目名称:httpclient,代码行数:44,代码来源:RestClient.java

示例3: configureSslSocketConnectionFactory

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private void configureSslSocketConnectionFactory(HttpClientBuilder builder, SslContextFactory sslContextFactory) {
    builder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContextFactory.createSslContext(), new DefaultHostnameVerifier(null)));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:4,代码来源:HttpClientConfigurer.java

示例4: usingHttpComponents

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options,
                                                    SslConfiguration sslConfiguration) throws GeneralSecurityException,
        IOException {

    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(
            DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));

    if (hasSslConfiguration(sslConfiguration)) {

        SSLContext sslContext = getSSLContext(sslConfiguration);
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                sslContext);
        httpClientBuilder.setSSLSocketFactory(sslSocketFactory);
        httpClientBuilder.setSslcontext(sslContext);
    }

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(options.getConnectionTimeout())
            .setSocketTimeout(options.getReadTimeout())
            .setAuthenticationEnabled(true)
            .build();

    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    // Support redirects
    httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());

    // Fix weird problem `ProtocolException: Content-Length header already present` from `org.apache.http.protocol.RequestContent`
    httpClientBuilder.addInterceptorFirst(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
            if (request instanceof HttpEntityEnclosingRequest) {
                request.removeHeaders(HTTP.TRANSFER_ENCODING);
                request.removeHeaders(HTTP.CONTENT_LEN);
            }
        }
    });

    return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:43,代码来源:ClientHttpRequestFactoryFactory.java

示例5: createHttpClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private static CloseableHttpClient createHttpClient() {
    HttpClientBuilder httpClientBuilder = HttpClients.custom();
    httpClientBuilder.setSSLSocketFactory(SSL_SOCKET_FACTORY);
    return httpClientBuilder.build();
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:6,代码来源:HttpClient.java


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