當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。