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


Java SSLContexts.createSystemDefault方法代码示例

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


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

示例1: initBase

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
protected void initBase() {
       SSLContext sslContext = SSLContexts.createSystemDefault();
       SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
               sslContext,
               SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);

       httpRequestConfig = RequestConfig.custom()
               .setSocketTimeout(TIMEOUT)
               .setConnectTimeout(TIMEOUT)
               .setCookieSpec(CookieSpecs.BEST_MATCH)
               .build();

       cookieStore = new BasicCookieStore();

       httpClient = HttpClientBuilder.create()
           .setSSLSocketFactory(sslsf)
           .setDefaultCookieStore(cookieStore)
           .setDefaultRequestConfig(httpRequestConfig)
               .build();


	localContext = HttpClientContext.create();

}
 
开发者ID:Naiqus,项目名称:E1zone_Android_Client,代码行数:25,代码来源:MyWebClient.java

示例2: initBase

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
protected void initBase() {
        //Initiate SSLSocketFactory. "java.lang.IllegalArgumentException: Item may not be null" error fixed.
        SSLContext sslContext = SSLContexts.createSystemDefault();
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                sslContext,
                SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);

		httpClient = HttpClientBuilder.create()
            .setSSLSocketFactory(sslsf)
                .build();

//		httpRequestConfig = RequestConfig.custom()
//		        .setSocketTimeout(TIMEOUT)
//		        .setConnectTimeout(TIMEOUT)
//		        .build();
		
		localContext = new BasicHttpContext();
	}
 
开发者ID:zeusbaba,项目名称:discourse-api-client,代码行数:19,代码来源:MyWebClient.java

示例3: ConnectionManager

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
public ConnectionManager() {
    loggedIn = false;
    SSLContext sslContext = SSLContexts.createSystemDefault();
    LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);

    PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager();
    pcm.setMaxTotal(100);
    pcm.setDefaultMaxPerRoute(50);

    HttpCompressionRequestInterceptor requestInterceptor = new HttpCompressionRequestInterceptor();
    HttpCompressionResponseInterceptor responseInterceptor = new HttpCompressionResponseInterceptor();

    httpClient = HttpClients.custom()
            .setConnectionManager(pcm)
            .setSSLSocketFactory(sslSocketFactory)
            .addInterceptorFirst(requestInterceptor)
            .addInterceptorFirst(responseInterceptor)
            .build();
}
 
开发者ID:polyglot-mark,项目名称:salesforce-plugin,代码行数:20,代码来源:ConnectionManager.java

示例4: createSslSocketFactory

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
private SSLConnectionSocketFactory createSslSocketFactory(Configuration configuration) {
    X509HostnameVerifier verifier;
    if (configuration.isApiSslCnCheck()) {
        verifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
    } else {
        verifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
    }

    // Remove SSLv2Hello and SSLv3 from the allowed ciphers list
    // Java 7u75 disabled them anyway, so usually the MyTimetable server will not support these protocols
    SSLContext sslContext = SSLContexts.createSystemDefault();
    Set<String> enabledProtocols = new HashSet<String>();
    for (String s : sslContext.getDefaultSSLParameters().getProtocols()) {
        if (s.equals("SSLv3") || s.equals("SSLv2Hello")) {
            continue;
        }
        enabledProtocols.add(s);
    }

    return new SSLConnectionSocketFactory(sslContext,
            enabledProtocols.toArray(new String[enabledProtocols.size()]), null, verifier);
}
 
开发者ID:eveoh,项目名称:mytimetable-api-client,代码行数:23,代码来源:MyTimetableHttpClientBuilderImpl.java

示例5: getLenientSslSocketFactory

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
private SSLConnectionSocketFactory getLenientSslSocketFactory()
{
    SSLContext sslContext = SSLContexts.createSystemDefault();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            sslContext,
            SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    return sslsf;
}
 
开发者ID:kenwdelong,项目名称:stability-utils,代码行数:9,代码来源:PooledHttpClientStrategy.java

示例6: createHttpClient

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
private HttpClient createHttpClient(ConnectionConfig config) {
  RequestConfig requestConfig = RequestConfig.custom()
      .setConnectTimeout(config.getConnectionTimeoutMs())
      .setSocketTimeout(config.getSocketTimeoutMs())
      .build();

  RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
  registryBuilder.register("http", new PlainConnectionSocketFactory());

  if (config.isHttpsEnabled()) {
    SSLContext sslContext = SSLContexts.createSystemDefault();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
        sslContext,
        SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registryBuilder.register("https", sslsf);
  }
  connectionManager = new PoolingHttpClientConnectionManager(registryBuilder.build());
  connectionManager.setDefaultMaxPerRoute(config.getMaxConnection());
  connectionManager.setMaxTotal(config.getMaxConnection());

  HttpClient httpClient = HttpClients.custom()
      .setConnectionManager(connectionManager)
      .setDefaultRequestConfig(requestConfig)
      .setRetryHandler(new DefaultHttpRequestRetryHandler(3, false))
      .build();
  return httpClient;
}
 
开发者ID:XiaoMi,项目名称:galaxy-sdk-java,代码行数:28,代码来源:BaseClient.java

示例7: buildClient

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
/**
 * Builds the HTTP client to connect to the server.
 * 
 * @param trustSelfSigned <tt>true</tt> if the client should accept
 *            self-signed certificates
 * @return a new client instance
 */
private CloseableHttpClient buildClient(boolean trustSelfSigned) {
	try {
		// if required, define custom SSL context allowing self-signed certs
		SSLContext sslContext = !trustSelfSigned ? SSLContexts.createSystemDefault()
			: SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

		// set timeouts for the HTTP client
		int globalTimeout = readFromProperty("bdTimeout", 100000);
		int connectTimeout = readFromProperty("bdConnectTimeout", globalTimeout);
		int connectionRequestTimeout = readFromProperty("bdConnectionRequestTimeout", globalTimeout);
		int socketTimeout = readFromProperty("bdSocketTimeout", globalTimeout);
		RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT).setConnectTimeout(connectTimeout)
			.setSocketTimeout(socketTimeout).setConnectionRequestTimeout(connectionRequestTimeout).build();

		// configure caching
		CacheConfig cacheConfig = CacheConfig.copy(CacheConfig.DEFAULT).setSharedCache(false).setMaxCacheEntries(1000)
			.setMaxObjectSize(2 * 1024 * 1024).build();

		// configure connection pooling
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(RegistryBuilder
			.<ConnectionSocketFactory> create().register("http", PlainConnectionSocketFactory.getSocketFactory())
			.register("https", new SSLConnectionSocketFactory(sslContext)).build());
		int connectionLimit = readFromProperty("bdMaxConnections", 40);
		// there's only one server to connect to, so max per route matters
		connManager.setMaxTotal(connectionLimit);
		connManager.setDefaultMaxPerRoute(connectionLimit);

		// create the HTTP client
		return CachingHttpClientBuilder.create().setCacheConfig(cacheConfig).setDefaultRequestConfig(requestConfig)
			.setConnectionManager(connManager).build();
	} catch (GeneralSecurityException e) {
		throw new InternalConfigurationException("Failed to set up SSL context", e);
	}
}
 
开发者ID:BellaDati,项目名称:belladati-sdk-java,代码行数:42,代码来源:BellaDatiClient.java

示例8: executePostWithForm

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
public static InputStream executePostWithForm(String targetURL, List<Property> properties)
		throws ClientProtocolException, IOException {
	// Create SSL Client
	SSLContext sslcontext = SSLContexts.createSystemDefault();
	SSLConnectionSocketFactory sslConnectionSocketFactory = 
		new SSLConnectionSocketFactory(
				sslcontext,
				new String[] { "TLSv1", "SSLv3" },
				null,
				SSLConnectionSocketFactory.getDefaultHostnameVerifier());		
	Registry<ConnectionSocketFactory> socketFactoryRegistry = 
		RegistryBuilder.<ConnectionSocketFactory>create()
			.register("http", PlainConnectionSocketFactory.INSTANCE)
			.register("https", sslConnectionSocketFactory)
			.build();
	PoolingHttpClientConnectionManager cm = 
		new PoolingHttpClientConnectionManager(socketFactoryRegistry);		
	CloseableHttpClient httpClient = HttpClients.custom()
		.setSSLSocketFactory(sslConnectionSocketFactory)
		.setConnectionManager(cm)
		.build();

	MultipartEntityBuilder builder = MultipartEntityBuilder.create();
	for (Property p : properties)
		builder.addTextBody(p.key, p.value, ContentType.TEXT_PLAIN);
	HttpPost uploadFile = new HttpPost(targetURL);
	uploadFile.setEntity(builder.build());

	// Send POST
	CloseableHttpResponse response = httpClient.execute(uploadFile);
	
	int status = response.getStatusLine().getStatusCode();
	if ((status == HttpURLConnection.HTTP_MOVED_TEMP
			|| status == HttpURLConnection.HTTP_MOVED_PERM
			|| status == HttpURLConnection.HTTP_SEE_OTHER)) {
		System.out.println("Got status " + status);

		// Get redirect url from "location" header field
		String newURL = response.getFirstHeader("Location").getValue();
		System.out.println("Redirect to URL: " + newURL);

		// Send the new POST
		uploadFile = new HttpPost(newURL);
		uploadFile.setEntity(builder.build());
		response = httpClient.execute(uploadFile);
	}

	// Get response
	return response.getEntity().getContent();
}
 
开发者ID:nevesnunes,项目名称:mid,代码行数:51,代码来源:Requester.java

示例9: createHttpClient

import org.apache.http.conn.ssl.SSLContexts; //导入方法依赖的package包/类
private HttpClient createHttpClient(FDSClientConfiguration config) {
  RequestConfig requestConfig = RequestConfig.custom()
      .setConnectTimeout(config.getConnectionTimeoutMs())
      .setSocketTimeout(config.getSocketTimeoutMs())
      .build();

  RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
  registryBuilder.register("http", new ConnectionInfoRecorderSocketFactory(
      new PlainConnectionSocketFactory()));

  if (config.isHttpsEnabled()) {
    SSLContext sslContext = SSLContexts.createSystemDefault();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
        sslContext,
        SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registryBuilder.register("https", new ConnectionInfoRecorderSocketFactory(sslsf));
  }
  ipBlackList = new TimeBasedIpAddressBlackList(config.getIpAddressNegativeDurationMillsec());
  connectionManager = new PoolingHttpClientConnectionManager(registryBuilder.build(),
      null,
      null,
      new RoundRobinDNSResolver(new InternalSiteBlackListDNSResolver(ipBlackList,
          this.dnsResolver == null ?
              SystemDefaultDnsResolver.INSTANCE : this.dnsResolver)),
      config.getHTTPKeepAliveTimeoutMS(), TimeUnit.MILLISECONDS);
  connectionManager.setDefaultMaxPerRoute(config.getMaxConnection());
  connectionManager.setMaxTotal(config.getMaxConnection());

  FDSBlackListEnabledHostChecker fdsBlackListEnabledHostChecker = new FDSBlackListEnabledHostChecker();
  retryHandler = new InternalIpBlackListRetryHandler(config.getRetryCount(),
      ipBlackList, fdsBlackListEnabledHostChecker);
  HttpClient httpClient = HttpClients.custom()
      .setRetryHandler(retryHandler)
      .setServiceUnavailableRetryStrategy(new ServiceUnavailableDNSBlackListStrategy(
          config.getRetryCount(),
          config.getRetryIntervalMilliSec(),
          ipBlackList,
          fdsBlackListEnabledHostChecker))
      .setConnectionManager(connectionManager)
      .setDefaultRequestConfig(requestConfig)
      .build();
  return httpClient;
}
 
开发者ID:XiaoMi,项目名称:galaxy-fds-sdk-java,代码行数:44,代码来源:GalaxyFDSClient.java


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