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


Java SSLContextBuilder.loadTrustMaterial方法代碼示例

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


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

示例1: createSSLConnectionSocketFactory

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private static SSLConnectionSocketFactory createSSLConnectionSocketFactory(Path path, char[] password, boolean strict, KeystoreType keystoreType) {
	try {
		SSLContextBuilder builder = SSLContexts.custom();
		if (path != null) {
			KeyStore trustStore = KeyStore.getInstance(keystoreType.name());
			try (InputStream is = Files.newInputStream(path)) {
				trustStore.load(is, password);
			}

			builder.loadTrustMaterial(trustStore);
		} else {
			builder.loadTrustMaterial(null, new TrustEverythingStrategy());
		}

		X509HostnameVerifier verifier;
		if (strict) {
			verifier = SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER;
		} else {
			verifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
		}

		return new SSLConnectionSocketFactory(builder.build(), new String[] {"TLSv1", "TLSv1.2"}, null, verifier);
	} catch (IOException | GeneralSecurityException ex) {
		throw new RuntimeException("Can't create SSL connection factory", ex);
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:27,代碼來源:HttpClient.java

示例2: getInstance

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public static SSLConnectionSocketFactory getInstance() {
    if (sslConnectionSocketFactory == null) {
        synchronized (ConnectionManagerFactory.class) {
            if (sslConnectionSocketFactory == null) {
                try{
                    SSLContextBuilder builder = new SSLContextBuilder();
                    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
                    sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build());
                }catch(Exception exception){
                    exception.getStackTrace();
                }
            }
        }
    }
    return sslConnectionSocketFactory;
}
 
開發者ID:DISSIDIA-986,項目名稱:EncDecAboutJava,代碼行數:17,代碼來源:SSLFactory.java

示例3: getSSLSocketFactory

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private SSLConnectionSocketFactory getSSLSocketFactory() {
    KeyStore trustStore;
    try {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        TrustStrategy trustStrategy = new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }

        };

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
        sslContextBuilder.useTLS();
        SSLContext sslContext = sslContextBuilder.build();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
        return sslSocketFactory;
    } catch (GeneralSecurityException | IOException e) {
        System.err.println("SSL Error : " + e.getMessage());
    }
    return null;
}
 
開發者ID:Esri,項目名稱:performance-test-harness-for-geoevent,代碼行數:25,代碼來源:GeoEventProvisioner.java

示例4: createSslHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private CloseableHttpClient createSslHttpClient() throws Exception {
    final SSLContextBuilder wsBuilder = new SSLContextBuilder();
    wsBuilder.loadTrustMaterial(null, new TrustStrategy() {
        @Override
        public boolean isTrusted(X509Certificate[] chain,
            String authType) throws CertificateException {
            return true;
        }
    });
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(wsBuilder.build(),
        new AllowAllHostnameVerifier());
    //This winds up using a PoolingHttpClientConnectionManager so need to pass the
    //RegistryBuilder
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder
        .<ConnectionSocketFactory> create().register("https", sslsf)
        .build();
    final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
    return HttpClients
        .custom()
        .setConnectionManager(cm)
        .build();

}
 
開發者ID:apache,項目名稱:tinkerpop,代碼行數:24,代碼來源:AbstractGremlinServerChannelizerIntegrateTest.java

示例5: createHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public CloseableHttpClient createHttpClient(boolean allowSelfSigned)
		throws IOException {
	CloseableHttpClient httpclient = null;

	if (allowSelfSigned) {
		try {
			SSLContextBuilder builder = new SSLContextBuilder();
			builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
			SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
					builder.build(),
					SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
			httpclient = HttpClients.custom().setSSLSocketFactory(sslsf)
					.setDefaultCookieStore(cookieStore).build();
		} catch (Exception e) {
			throw new IOException(e);
		}

	} else {
		httpclient = HttpClients.custom()
				.setDefaultCookieStore(cookieStore).build();
	}

	return httpclient;
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:25,代碼來源:HttpUtilsHolder.java

示例6: RestClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public RestClient() throws Exception {
    SSLContextBuilder builder = new SSLContextBuilder();
    SSLConnectionSocketFactory sslConnectionFactory;
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    sslConnectionFactory = new SSLConnectionSocketFactory(builder.build());
    this.httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionFactory)
            .setConnectionManager(HTTPConnectionManager.getInstance().getHttpConnectionManager()).build();
}
 
開發者ID:apache,項目名稱:stratos,代碼行數:9,代碼來源:RestClient.java

示例7: RestClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public RestClient(String baseUrl) throws Exception {
	this.baseUrl = baseUrl;
	SSLContextBuilder builder = new SSLContextBuilder();
	builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
	this.httpclient = HttpClients.custom().setUserAgent("r2cloud/0.1 [email protected]").setSSLSocketFactory(sslsf).build();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:8,代碼來源:RestClient.java

示例8: createUnsafeClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public static HttpClient createUnsafeClient() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                builder.build());
        return HttpClients.custom()
                .setSSLSocketFactory(sslsf).build();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:13,代碼來源:UnsafeHttpsClient.java

示例9: setClientToSelfSigned

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * Create a HTTP client that uses a self-signed and always trusted
 * SSL strategy.
 *
 * @param custom The client builder
 * @return builder with unsafe SSL strategy
 * @throws APIException If there is a problem creating the client or strategy
 */
private HttpClientBuilder setClientToSelfSigned( final HttpClientBuilder custom ) throws APIException
{
  final SSLContextBuilder builder = new SSLContextBuilder();
  try {
    builder.loadTrustMaterial( null, new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory( builder.build());
    return custom.setSSLSocketFactory( sf );
  } catch( NoSuchAlgorithmException | KeyStoreException | KeyManagementException e ) {
    throw new APIException( "Failed to create self-signed trust strategy and/or SSL-enabled HTTP Client", e );
  }
}
 
開發者ID:SixArmDonkey,項目名稱:aerodrome-for-jet,代碼行數:20,代碼來源:APIHttpClient.java

示例10: init

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public static void init() throws RuntimeException {
        try {
            logger.warn(NOTICELINE + " httpUtil init begin " + NOTICELINE);
            SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
//            sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
            sslContextBuilder.loadTrustMaterial(null,new TrustAnyTrustManager());
            SSLConnectionSocketFactory sslConnectionSocketFactory =
                    new SSLConnectionSocketFactory(
                            sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().
                    register("http", new PlainConnectionSocketFactory()).
                    register("https", sslConnectionSocketFactory).
                    build();


            logger.warn(NOTICELINE + " SSL context init done " + NOTICELINE);

            //init connectionManager , ThreadSafe pooled conMgr
            PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registry);
            poolingHttpClientConnectionManager.setMaxTotal(30);
            poolingHttpClientConnectionManager.setDefaultMaxPerRoute(3);
            //init request config. pooltimeout,sotime,contimeout
            RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(POOL_TIMECOUT).setConnectTimeout(CON_TIMEOUT).setSocketTimeout(SO_TIMEOUT).build();
            // begin construct httpclient
            HttpClientBuilder httpClientBuilder = HttpClients.custom();
            httpClientBuilder.setConnectionManager(poolingHttpClientConnectionManager);
            httpClientBuilder.setDefaultRequestConfig(requestConfig);
            httpClientBuilder.setRetryHandler(new HttpRequestRetryHandler() {
                @Override
                public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                    if (executionCount >= HTTP_RETRY_COUNT) {
                        return false;
                    }
                    if (exception instanceof InterruptedIOException) {
                        // Timeout
                        logger.warn("httpUtil retry for InterruptIOException");
                        return true;
                    }
                    if (exception instanceof UnknownHostException) {
                        // Unknown host
                        return false;
                    }
                    if (exception instanceof SSLException) {
                        // SSL handshake exception
                        return false;
                    }
                    HttpClientContext clientContext = HttpClientContext.adapt(context);
                    HttpRequest request = clientContext.getRequest();
                    boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
                    if (idempotent) {
                        // Retry if the request is considered idempotent
                        logger.warn("httpUtil retry for idempotent");
                        return true;
                    }
                    return false;
                }
            });
            logger.warn(NOTICELINE + " poolManager , requestconfig init done " + NOTICELINE);

            httpclient = httpClientBuilder.build();
            logger.warn(NOTICELINE + " httpUtil init done " + NOTICELINE);
        } catch (Exception e) {
            logger.error(NOTICELINE + "httpclient init fail" + NOTICELINE, e);
            throw new RuntimeException(e);
        }
    }
 
開發者ID:zhengjunbase,項目名稱:codehelper.generator,代碼行數:68,代碼來源:HttpUtil.java

示例11: createUnsafeClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
public static HttpClient createUnsafeClient() {
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
				builder.build());
		CloseableHttpClient httpclient = HttpClients.custom()
				.setSSLSocketFactory(sslsf).build();

		return httpclient;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:juleswhite,項目名稱:CSX278,代碼行數:15,代碼來源:UnsafeHttpsClient.java

示例12: createHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private static CloseableHttpClient createHttpClient() {
    try {
        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslSocketFactory =
                new SSLConnectionSocketFactory(sslContextBuilder.build(),
                                               SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        return HttpClientBuilder.create().setSSLSocketFactory(sslSocketFactory).build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:13,代碼來源:IdentityDocumentService.java

示例13: createHttpClientThatAcceptsAllServerCerts

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
private static CloseableHttpClient createHttpClientThatAcceptsAllServerCerts()
        throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    final SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, (chain, authType) -> true);
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
    return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
 
開發者ID:eclipse,項目名稱:hawkbit-examples,代碼行數:8,代碼來源:DeviceSimulatorUpdater.java

示例14: getHttpClient

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
/**
 * Return a http client instance
 *
 * @param protocol- service endpoint protocol http/https
 * @return
 */
public static HttpClient getHttpClient(String protocol)
		throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
	HttpClient httpclient;
	if (HTTPS_PROTOCOL.equals(protocol)) {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
		httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
	} else {
		httpclient = HttpClients.createDefault();
	}
	return httpclient;
}
 
開發者ID:wso2,項目名稱:carbon-device-mgt,代碼行數:20,代碼來源:JWTClientUtil.java

示例15: createSslContext

import org.apache.http.conn.ssl.SSLContextBuilder; //導入方法依賴的package包/類
protected SSLContext createSslContext() {
    try {
        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(null, ACCEPT_ANY_CERTIFICATE_TRUST_STRATEGY);
        return sslContextBuilder.build();
    } catch (KeyManagementException | KeyStoreException | NoSuchAlgorithmException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:10,代碼來源:CommonHttpClientBuilder.java


注:本文中的org.apache.http.conn.ssl.SSLContextBuilder.loadTrustMaterial方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。