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


Java SSLContextBuilder.build方法代码示例

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


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

示例1: init

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public void init() {
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
		/* 配置同时支持 HTTP 和 HTPPS */
		Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
				.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
		/* 初始化连接管理器 */
		poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
		poolConnManager.setMaxTotal(maxTotal);
		poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
				.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
		httpClient = getConnection();
		log.info("HttpConnectionManager初始化完成...");
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:21,代码来源:HttpConnectionManager.java

示例2: createAllTrustingClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
private static HttpClient createAllTrustingClient() throws RestClientException {
	HttpClient httpclient = null;
	try {
		final SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial((TrustStrategy) (X509Certificate[] chain, String authType) -> true);
		final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
				builder.build());
		httpclient = HttpClients
				.custom()
				.setSSLSocketFactory(sslsf)
				.setMaxConnTotal(1000)
				.setMaxConnPerRoute(1000)
				.build();
	} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
		throw new RestClientException("Cannot create all SSL certificates trusting client", e);
	}
	return httpclient;
}
 
开发者ID:syndesisio,项目名称:syndesis-qe,代码行数:19,代码来源:RestUtils.java

示例3: triggerHttpGetWithCustomSSL

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public static String triggerHttpGetWithCustomSSL(String requestUrl) {
	String result = null;
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
			public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
				return true;
			}
		});
		@SuppressWarnings("deprecation")
		HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), hostnameVerifier);

		CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

		HttpGet httpGet = new HttpGet("https://" + requestUrl);
		CloseableHttpResponse response = httpclient.execute(httpGet);
		try {
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				HttpEntity entity = response.getEntity();
				result = EntityUtils.toString(entity);
				log.debug("Received response: " + result);
			} else {
				log.error("Request not successful. StatusCode was " + response.getStatusLine().getStatusCode());
			}
		} finally {
			response.close();
		}
	} catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		log.error("Error executing the request.", e);
	}
	return result;
}
 
开发者ID:hotstepper13,项目名称:alexa-gira-bridge,代码行数:35,代码来源:Util.java

示例4: init

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public void init()
{
  try
  {
    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    Unirest.setHttpClient(httpclient);
  }
  catch (Exception e)
  {
    System.out.println("Failed to start server: " + e.toString());
    e.printStackTrace();
  }
}
 
开发者ID:Malow,项目名称:GladiatorManager,代码行数:17,代码来源:ServerConnection.java

示例5: buildHttpClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * This creates a HTTP client instance for connecting the IFTTT server.
 * 
 * @return the HTTP client instance
 */
private CloseableHttpClient buildHttpClient ()
{
    if ( configuration.isIftttIgnoreServerCertificate() ) {
        try {
            SSLContextBuilder builder = new SSLContextBuilder();
            builder.loadTrustMaterial(new TrustStrategy() {
                @Override
                public boolean isTrusted (X509Certificate[] chain_, String authType_) throws CertificateException
                {
                    return true;
                }
            });
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();
        }
        catch (Exception ex) {
            LOG.error(ex);
            // This should never happen, but we have to handle it
            throw new RuntimeException(ex);
        }
    }
    else {
        return HttpClients.createDefault();
    }
}
 
开发者ID:zazaz-de,项目名称:iot-device-bosch-indego-controller,代码行数:31,代码来源:IftttIndegoAdapter.java

示例6: getHttpsClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
private CloseableHttpClient getHttpsClient()
{
    try
    {
        RequestConfig config = RequestConfig.custom().setSocketTimeout( 5000 ).setConnectTimeout( 5000 ).build();

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial( null, ( TrustStrategy ) ( x509Certificates, s ) -> true );
        SSLConnectionSocketFactory sslSocketFactory =
                new SSLConnectionSocketFactory( sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE );

        return HttpClients.custom().setDefaultRequestConfig( config ).setSSLSocketFactory( sslSocketFactory )
                          .build();
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return HttpClients.createDefault();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:22,代码来源:RestServiceImpl.java

示例7: configureInsecureSSL

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * Allow SSL connections to utilize untrusted certificates
 * 
 * @param httpClientBuilder
 * @throws MojoExecutionException
 */
private void configureInsecureSSL(HttpClientBuilder httpClientBuilder) throws MojoExecutionException {
    try {
        SSLContextBuilder sslBuilder = new SSLContextBuilder();

        // Accept all Certificates
        sslBuilder.loadTrustMaterial(null, AcceptAllTrustStrategy.INSTANCE);

        SSLContext sslContext = sslBuilder.build();

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
                NoopHostnameVerifier.INSTANCE);
        httpClientBuilder.setSSLSocketFactory(sslsf);
    } catch (Exception e) {
        throw new MojoExecutionException("Error setting insecure SSL configuration", e);
    }
}
 
开发者ID:sabre1041,项目名称:jenkinsfile-maven-plugin,代码行数:23,代码来源:ValidateJenkinsfileMojo.java

示例8: HttpPosterThread

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
HttpPosterThread(LinkedBlockingQueue<String> lbq, String url) throws Exception {
    this.lbq = lbq;
    this.url = url;

    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            builder.build());
    httpClient = HttpClients.custom().setSSLSocketFactory(
            sslsf).build();

    //httpClient = HttpClientBuilder.create().build();
    httpPost = new HttpPost(url);

    cntErr = 0;
}
 
开发者ID:david618,项目名称:Simulator,代码行数:17,代码来源:HttpPosterThread.java

示例9: createInsecureSslFactory

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * This method creates an insecure SSL factory that will trust on self signed certificates.
 * For that we use {@link TrustSelfSignedStrategy}.
 */
protected SSLConnectionSocketFactory createInsecureSslFactory() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());
        SSLContext sc = builder.build();

        if (acceptAllKindsOfCertificates) {
            TrustManager[] trustAllCerts = new TrustManager[1];
            TrustManager tm = new TrustAllManager();
            trustAllCerts[0] = tm;
            sc.init(null, trustAllCerts, null);

            HostnameVerifier hostnameVerifier = createInsecureHostNameVerifier();
            return new SSLConnectionSocketFactory(sc, hostnameVerifier);
        }
        return new SSLConnectionSocketFactory(sc);
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        throw new ApacheCloudStackClientRuntimeException(e);
    }
}
 
开发者ID:Autonomiccs,项目名称:apache-cloudstack-java-client,代码行数:25,代码来源:ApacheCloudStackClient.java

示例10: TankHttpClient4

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * no-arg constructor for client
 */
public TankHttpClient4() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
    } catch (Exception e) {
        LOG.error("Error setting accept all: " + e, e);
    }

    httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    requestConfig = RequestConfig.custom().setSocketTimeout(30000)
    		.setConnectTimeout(30000)
    		.setCircularRedirectsAllowed(true)
    		.setAuthenticationEnabled(true)
    		.setRedirectsEnabled(true)
    		.setCookieSpec(CookieSpecs.STANDARD)
            .setMaxRedirects(100).build();

    // Make sure the same context is used to execute logically related
    // requests
    context = HttpClientContext.create();
    context.setCredentialsProvider(new BasicCredentialsProvider());
    context.setCookieStore(new BasicCookieStore());
    context.setRequestConfig(requestConfig);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:29,代码来源:TankHttpClient4.java

示例11: getHttpClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
private HttpClient getHttpClient() {
    CloseableHttpClient httpclient = null;

    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(keyStore, (TrustStrategy) (trustedCert, nameConstraints) -> true);

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
        httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        _logger.error("Failed to create HTTPClient: {}", e);
    }

    return httpclient;
}
 
开发者ID:hawkular,项目名称:hawkular-client-java,代码行数:17,代码来源:RestFactory.java

示例12: getAuthenticatedClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public CloseableHttpClient getAuthenticatedClient() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                builder.build(), NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .setDefaultCredentialsProvider(getCredentialsProvider())
                .build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        Logger.getLogger(AuthHandler.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:curly,代码行数:17,代码来源:AuthHandler.java

示例13: createSslCustomContext

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
private SSLContext createSslCustomContext() {
    try {
        SSLContextBuilder builder = SSLContexts.custom();
        if (options.getKeystore().isPresent()) {
            KeyStore cks = KeyStore.getInstance(KeyStore.getDefaultType());
            cks.load(new FileInputStream(options.getKeystore().get().toFile()), options.getKeystorePass().toCharArray());
            builder.loadKeyMaterial(cks, options.getKeystorePass().toCharArray());
        }

        if (options.getTruststore().isPresent()) {
            KeyStore tks = KeyStore.getInstance(KeyStore.getDefaultType());
            tks.load(new FileInputStream(options.getTruststore().get().toFile()), options.getTruststorePass().toCharArray());
            builder.loadTrustMaterial(tks, new TrustSelfSignedStrategy());
        }

        if (!options.getKeystore().isPresent() && !options.getKeystore().isPresent()) {
            return SSLContext.getDefault();
        }

        return builder.build();
    } catch (Exception e) {
        // TODO: DO SOMETHING WITH THE EXCEPTION!
        LOG.error("Exception", e);
    }
    return null;
}
 
开发者ID:ULYSSIS-KUL,项目名称:ipp,代码行数:27,代码来源:HttpOutput.java

示例14: trustSelfSignedCerts

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * Adds the ability to trust self signed certificates for this HttpClientBuilder
 * 
 * @param httpClientBuilder
 * the HttpClientBuilder to apply these settings to
 */
public static void trustSelfSignedCerts(final HttpClientBuilder httpClientBuilder)
{
	logger.debug("Trusting self-signed certs.");
	try
	{
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
			builder.build(), new HostnameVerifier()
			{
				@Override
				public boolean verify(String hostname, SSLSession session)
				{
					// allow all
					return true;
				}
			});
			
		httpClientBuilder.setSSLSocketFactory(sslsf);
	}
	catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex)
	{
		logger.error("Error adding SSLSocketFactory to HttpClientBuilder", ex);
	}
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:32,代码来源:ConnectionUtil.java

示例15: getFactoryDisabledSslChecks

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
/**
 * WARNING!!! disabling is not a good idea.
 * 
 * Support hardcode for ps team
 * 
 * Their server is pretty busted. -
 * http://stackoverflow.com/questions/7615645
 * /ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0
 * -- -Djsse.enableSNIExtension=false very ugly workaround
 * 
 * @param restTemplate
 * @throws Exception
 */
public static HttpComponentsClientHttpRequestFactory getFactoryDisabledSslChecks(
		int connectTimeoutMs, int readTimeoutMs) throws Exception {

	SSLContextBuilder builder = new SSLContextBuilder();
	builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
	// builder.loadTrustMaterial(null, new TrustStrategy() {
	//
	// @Override
	// public boolean isTrusted(X509Certificate[] chain, String authType)
	// throws CertificateException {
	//
	// return true;
	// }
	// });

	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
			builder.build(), new NoopHostnameVerifier());

	CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(
			sslsf).build();

	HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
	factory.setHttpClient(httpClient);
	// factory.getHttpClient().getConnectionManager().getSchemeRegistry().register(scheme);

	factory.setConnectTimeout(connectTimeoutMs);
	factory.setReadTimeout(readTimeoutMs);

	// restTemplate.setRequestFactory(factory);
	return factory;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:45,代码来源:NagiosIntegration.java


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