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