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


Java SSLContextBuilder.loadTrustMaterial方法代码示例

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


在下文中一共展示了SSLContextBuilder.loadTrustMaterial方法的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: setTrustedKeystore

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public void setTrustedKeystore(final RestSettings.Keystore keystore) throws Exception {
    final SSLContextBuilder ssl = SSLContexts.custom();

    final String path = keystore.getPath();
    final String password = keystore.getPassword();

    final URL resource = HttpClientFactoryBean.class.getClassLoader().getResource(path);

    if (resource == null) {
        throw new FileNotFoundException(format("Keystore [%s] not found.", path));
    }

    try {
        ssl.loadTrustMaterial(resource, password == null ? null : password.toCharArray());
        builder.setSSLSocketFactory(new SSLConnectionSocketFactory(ssl.build(), getDefaultHostnameVerifier()));
    } catch (final Exception e) {
        LOG.error("Error loading keystore [{}]:", path, e); // log full exception, bean initialization code swallows it
        throw e;
    }
}
 
开发者ID:zalando-stups,项目名称:put-it-to-rest,代码行数:21,代码来源:HttpClientFactoryBean.java

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

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

示例11: setTrustedKeystore

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
public void setTrustedKeystore(final Keystore keystore) throws Exception {
    final SSLContextBuilder ssl = SSLContexts.custom();

    final String path = keystore.getPath();
    final String password = keystore.getPassword();

    final URL resource = HttpClientFactoryBean.class.getClassLoader().getResource(path);

    if (resource == null) {
        throw new FileNotFoundException(format("Keystore [%s] not found.", path));
    }

    try {
        ssl.loadTrustMaterial(resource, password == null ? null : password.toCharArray());
        builder.setSSLSocketFactory(new SSLConnectionSocketFactory(ssl.build(), getDefaultHostnameVerifier()));
    } catch (final Exception e) {
        LOG.error("Error loading keystore [{}]:", path, e); // log full exception, bean initialization code swallows it
        throw e;
    }
}
 
开发者ID:zalando,项目名称:riptide,代码行数:21,代码来源:HttpClientFactoryBean.java

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

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

示例14: getHttpClient

import org.apache.http.ssl.SSLContextBuilder; //导入方法依赖的package包/类
protected HttpClient getHttpClient(Map<String, Object> options) throws GeneralSecurityException {
    SocketConfig socketConfig = SocketConfig.custom()
            .setSoKeepAlive(true).build();

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    httpClientBuilder.setDefaultSocketConfig(socketConfig);
    httpClientBuilder.disableAuthCaching();
    httpClientBuilder.disableAutomaticRetries();

    if(options.containsKey("sslVerify") && !Boolean.parseBoolean(options.get("sslVerify").toString())) {
        log.debug("Disabling all SSL certificate verification.");
        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(null, new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                return true;
            }
        });

        httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
        httpClientBuilder.setSSLContext(sslContextBuilder.build());
    }

    return httpClientBuilder.build();
}
 
开发者ID:ohioit,项目名称:rundeck-http-plugin,代码行数:27,代码来源:HttpWorkflowStepPlugin.java

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


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