org.apache.http.conn.ssl.SSLSocketFactory.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(401)

本文整理了Java中org.apache.http.conn.ssl.SSLSocketFactory.<init>()方法的一些代码示例,展示了SSLSocketFactory.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLSocketFactory.<init>()方法的具体详情如下:
包路径:org.apache.http.conn.ssl.SSLSocketFactory
类名称:SSLSocketFactory
方法名:<init>

SSLSocketFactory.<init>介绍

[英]Creates the default SSL socket factory. This constructor is used exclusively to instantiate the factory for #getSocketFactory.
[中]创建默认的SSL套接字工厂。此构造函数专门用于实例化#getSocketFactory的工厂。

代码示例

代码示例来源:origin: robovm/robovm

private static class NoPreloadHolder {
  /**
   * The factory using the default JVM settings for secure connections.
   */
  private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory();
}

代码示例来源:origin: Netflix/eureka

/**
 * Since Jersey 1.19 depends on legacy apache http-client API, we have to as well.
 */
private ThreadSafeClientConnManager createConnectionManager() {
  try {
    ThreadSafeClientConnManager connectionManager;
    if (sslContext != null) {
      SchemeSocketFactory socketFactory = new SSLSocketFactory(sslContext, new AllowAllHostnameVerifier());
      SchemeRegistry sslSchemeRegistry = new SchemeRegistry();
      sslSchemeRegistry.register(new Scheme("https", 443, socketFactory));
      connectionManager = new ThreadSafeClientConnManager(sslSchemeRegistry);
    } else {
      connectionManager = new ThreadSafeClientConnManager();
    }
    return connectionManager;
  } catch (Exception e) {
    throw new IllegalStateException("Cannot initialize Apache connection manager", e);
  }
}

代码示例来源:origin: stackoverflow.com

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);

代码示例来源:origin: apache/kylin

public KylinClient(KylinConnectionInfo connInfo) {
  this.connInfo = connInfo;
  this.connProps = connInfo.getConnectionProperties();
  this.httpClient = new DefaultHttpClient();
  this.jsonMapper = new ObjectMapper();
  // trust all certificates
  if (isSSL()) {
    try {
      SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {
        public boolean isTrusted(final X509Certificate[] chain, String authType)
            throws CertificateException {
          // Oh, I am easy...
          return true;
        }
      });
      httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sslsf));
    } catch (Exception e) {
      throw new RuntimeException("Initialize HTTPS client failed", e);
    }
  }
}

代码示例来源:origin: stackoverflow.com

inputStream.close();
  ret = new SSLSocketFactory(ks);
} catch (UnrecoverableKeyException ex) {
  Log.d(TAG, ex.getMessage());

代码示例来源:origin: rest-assured/rest-assured

SSLSocketFactory sf = new SSLSocketFactory(sslContext, ALLOW_ALL_HOSTNAME_VERIFIER);
return sslSocketFactory(sf);

代码示例来源:origin: apache/nifi

final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory);
httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);

代码示例来源:origin: stackoverflow.com

in.close();
  return new SSLSocketFactory(trusted);
} catch (Exception e) {
  throw new AssertionError(e);

代码示例来源:origin: apache/cloudstack

public static HttpClient getHttpClient() {
  HttpClient httpClient = null;
  TrustStrategy easyStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
      return true;
    }
  };
  try {
    SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier());
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("https", DEFAULT_PORT, sf));
    ClientConnectionManager ccm = new BasicClientConnectionManager(registry);
    httpClient = new DefaultHttpClient(ccm);
  } catch (KeyManagementException e) {
    s_logger.error("failed to initialize http client " + e.getMessage());
  } catch (UnrecoverableKeyException e) {
    s_logger.error("failed to initialize http client " + e.getMessage());
  } catch (NoSuchAlgorithmException e) {
    s_logger.error("failed to initialize http client " + e.getMessage());
  } catch (KeyStoreException e) {
    s_logger.error("failed to initialize http client " + e.getMessage());
  }
  return httpClient;
}

代码示例来源:origin: apache/cloudstack

protected DefaultHttpClient getHttpsClient() {
  try {
    SSLContext sslContext = SSLUtils.getSSLContext();
    X509TrustManager tm = new X509TrustManager() {
      @Override
      public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
      }
      @Override
      public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
      }
      @Override
      public X509Certificate[] getAcceptedIssuers() {
        return null;
      }
    };
    sslContext.init(null, new TrustManager[] {tm}, new SecureRandom());
    SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("https", nmsUrl.getPort(), socketFactory));
    BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry);
    return new DefaultHttpClient(mgr);
  } catch (NoSuchAlgorithmException ex) {
    throw new CloudRuntimeException(ex.getMessage());
  } catch (KeyManagementException ex) {
    throw new CloudRuntimeException(ex.getMessage());
  }
}

代码示例来源:origin: apache/cloudstack

SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(verifier);
ClientConnectionManager ccm = base.getConnectionManager();

代码示例来源:origin: apache/cloudstack

final SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier());
final SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", DEFAULT_AGENT_PORT, sf));

代码示例来源:origin: com.jayway.restassured/rest-assured

SSLSocketFactory sf = new SSLSocketFactory(sslContext, ALLOW_ALL_HOSTNAME_VERIFIER);
return sslSocketFactory(sf);

代码示例来源:origin: apache/cloudstack

SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier());
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", DEFAULT_PORT, sf));

代码示例来源:origin: foxinmy/weixin4j

/**
 * 默认httpclient
 * 
 * @see <a
 *      href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a>
 * @param clientConnectionManager
 */
public HttpComponent4_1Factory() {
  PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();
  clientConnectionManager.setMaxTotal(30);
  clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager
      .getMaxTotal());
  httpClient = new DefaultHttpClient(clientConnectionManager);
  httpClient.getParams().setParameter(
      CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8);
  httpClient.getParams().setParameter(
      CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name());
  httpClient.getParams().setParameter(
      CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8);
  httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING,
      Consts.UTF_8);
  httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET,
      Consts.UTF_8);
  SSLSocketFactory socketFactory = new SSLSocketFactory(
      HttpClientFactory.allowSSLContext());
  socketFactory
      .setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  Scheme scheme = new Scheme("https", socketFactory, 443);
  httpClient.getConnectionManager().getSchemeRegistry().register(scheme);
}

代码示例来源:origin: foxinmy/weixin4j

private void resolveHttpParams(HttpParams params) {
  if (params != null) {
    if (params.getProxy() != null) {
      InetSocketAddress socketAddress = (InetSocketAddress) params
          .getProxy().address();
      HttpHost proxy = new HttpHost(socketAddress.getHostName(),
          socketAddress.getPort());
      httpClient.getParams().setParameter(
          ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    httpClient.getParams().setIntParameter(
        CoreConnectionPNames.CONNECTION_TIMEOUT,
        params.getConnectTimeout());
    httpClient.getParams().setIntParameter(
        CoreConnectionPNames.SO_TIMEOUT, params.getReadTimeout());
    if (params.getSSLContext() != null) {
      SSLSocketFactory socketFactory = new SSLSocketFactory(
          params.getSSLContext());
      if (params.getHostnameVerifier() != null) {
        socketFactory
            .setHostnameVerifier(new CustomHostnameVerifier(
                params.getHostnameVerifier()));
      }
      Scheme scheme = new Scheme("https", socketFactory, 443);
      httpClient.getConnectionManager().getSchemeRegistry()
          .register(scheme);
    }
  }
}

代码示例来源:origin: org.apache.activemq/activemq-all

private SchemeRegistry createSchemeRegistry() {
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  try {
    SSLSocketFactory sslSocketFactory = new SSLSocketFactory(createSocketFactory(),
        SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    schemeRegistry.register(new Scheme("https", getRemoteUrl().getPort(), sslSocketFactory));
    return schemeRegistry;
  } catch (Exception e) {
    throw new IllegalStateException("Failure trying to create scheme registry", e);
  }
}

代码示例来源:origin: MobiVM/robovm

private static class NoPreloadHolder {
  /**
   * The factory using the default JVM settings for secure connections.
   */
  private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

private static class NoPreloadHolder {
  /**
   * The factory using the default JVM settings for secure connections.
   */
  private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory();
}

代码示例来源:origin: qaprosoft/carina

public void setSSLContext(SSLContext sslContext) {
  SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext);
  SSLConfig sslConfig = new SSLConfig();
  sslConfig = sslConfig.sslSocketFactory(socketFactory);
  RestAssuredConfig cfg = new RestAssuredConfig();
  cfg = cfg.sslConfig(sslConfig);
  request = request.config(cfg);
}

相关文章