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

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

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

Scheme.<init>介绍

[英]Creates a new scheme. Whether the created scheme allows for layered connections depends on the class of factory.
[中]创建一个新方案。创建的方案是否允许分层连接取决于工厂的类别。

代码示例

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

HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

DefaultHttpClient client = new DefaultHttpClient();

SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

// Set verifier     
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

// Example send http request
final String url = "https://encrypted.google.com/";
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost);

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

SSLContext sslContext = SSLContext.getInstance("SSL");

// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
      public X509Certificate[] getAcceptedIssuers() {
          System.out.println("getAcceptedIssuers =============");
          return null;
      }

      public void checkClientTrusted(X509Certificate[] certs,
              String authType) {
          System.out.println("checkClientTrusted =============");
      }

      public void checkServerTrusted(X509Certificate[] certs,
              String authType) {
          System.out.println("checkServerTrusted =============");
      }
} }, new SecureRandom());

SSLSocketFactory sf = new SSLSocketFactory(sslContext);
Scheme httpsScheme = new Scheme("https", 443, sf);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(httpsScheme);

// apache HttpClient version >4.2 should use BasicClientConnectionManager
ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm);

代码示例来源:origin: mttkay/ignition

public void setPortForScheme(String scheme, int port) {
  Scheme _scheme = new Scheme(scheme, PlainSocketFactory.getSocketFactory(), port);
  httpClient.getConnectionManager().getSchemeRegistry().register(_scheme);
}

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

/**
   * @see SchemeRegistryFactory#createDefault()
   */
  private MonitoredConnectionManager createDefaultSslCM() {
    final SchemeRegistry registry = new SchemeRegistry();
    registry.register(
        new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(
        new Scheme("https", 443, new SSLSocketFactoryAdapter(SSLConnectionSocketFactory.getSocketFactory())));
    
    return new MonitoredConnectionManager(clientName, registry);
  }
}

代码示例来源: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: Netflix/eureka

private MonitoredConnectionManager createSystemSslCM() {
  MonitoredConnectionManager cm;
  SSLConnectionSocketFactory systemSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory();
  SSLSocketFactory sslSocketFactory = new SSLSocketFactoryAdapter(systemSocketFactory);
  SchemeRegistry sslSchemeRegistry = new SchemeRegistry();
  sslSchemeRegistry.register(new Scheme(PROTOCOL, HTTPS_PORT, sslSocketFactory));
  cm = new MonitoredConnectionManager(clientName, sslSchemeRegistry);
  return cm;
}

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

private HttpClient sslClient(HttpClient client) {
  try {
    X509TrustManager tm = new X509TrustManager() { 
      public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
      }

      public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
      }

      public X509Certificate[] getAcceptedIssuers() {
        return null;
      }
    };
    SSLContext ctx = SSLContext.getInstance("TLS");
    ctx.init(null, new TrustManager[]{tm}, null);
    SSLSocketFactory ssf = new MySSLSocketFactory(ctx);
    ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    ClientConnectionManager ccm = client.getConnectionManager();
    SchemeRegistry sr = ccm.getSchemeRegistry();
    sr.register(new Scheme("https", ssf, 443));
    return new DefaultHttpClient(ccm, client.getParams());
  } catch (Exception ex) {
    return null;
  }
}

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

SchemeRegistry sslSchemeRegistry = new SchemeRegistry();
sslSchemeRegistry.register(new Scheme(PROTOCOL, HTTPS_PORT, sslSocketFactory));

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

ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm,
    client.getParams());

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

// Do not do this in production!!!
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

DefaultHttpClient client = new DefaultHttpClient();

SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

// Set verifier     
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

// Example send http request
final String url = "https://encrypted.google.com/";  
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost);

代码示例来源:origin: k9mail/k-9

public WebDavHttpClient getHttpClient() throws MessagingException {
  if (httpClient == null) {
    httpClient = httpClientFactory.create();
    // Disable automatic redirects on the http client.
    httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);
    // Setup a cookie store for forms-based authentication.
    httpContext = new BasicHttpContext();
    authCookies = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);
    SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
    try {
      Scheme s = new Scheme("https", new WebDavSocketFactory(trustManagerFactory, hostname, 443), 443);
      reg.register(s);
    } catch (NoSuchAlgorithmException nsa) {
      Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient");
      throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa);
    } catch (KeyManagementException kme) {
      Timber.e(kme, "KeyManagementException in getHttpClient");
      throw new MessagingException("KeyManagementException in getHttpClient: ", kme);
    }
  }
  return httpClient;
}

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

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);

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

final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory);
httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);

代码示例来源: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: apache/cloudstack

ClientConnectionManager ccm = base.getConnectionManager();
  SchemeRegistry sr = ccm.getSchemeRegistry();
  sr.register(new Scheme("https", ssf, 443));
  return new DefaultHttpClient(ccm, base.getParams());
} catch (Exception ex) {

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

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));

代码示例来源: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: stackoverflow.com

SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", socketFactory, 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
DefaultHttpClient sClient = new DefaultHttpClient(conMgr, params);

代码示例来源: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: mttkay/ignition

protected void setupHttpClient() {
  BasicHttpParams httpParams = new BasicHttpParams();
  ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
  ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(
      DEFAULT_MAX_CONNECTIONS));
  ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
  HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT);
  HttpConnectionParams.setTcpNoDelay(httpParams, true);
  HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
  HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) {
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
  } else {
    // used to work around a bug in Android 1.6:
    // http://code.google.com/p/android/issues/detail?id=1946
    // TODO: is there a less rigorous workaround for this?
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
  }
  ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
  httpClient = new DefaultHttpClient(cm, httpParams);
}

相关文章