org.apache.http.conn.scheme.Scheme类的使用及代码示例

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

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

Scheme介绍

[英]Encapsulates specifics of a protocol scheme such as "http" or "https". Schemes are identified by lowercase names. Supported schemes are typically collected in a SchemeRegistry.

For example, to configure support for "https://" URLs, you could write code like the following:

Scheme https = new Scheme("https", new MySecureSocketFactory(), 443); 
SchemeRegistry.DEFAULT.register(https);

[中]

代码示例

代码示例来源: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);
try {
  KeyStore trusted = KeyStore.getInstance("BKS");
    trusted.load(in, "mysecret".toCharArray());
  } finally {
    in.close();
  SSLSocketFactory sf = new SSLSocketFactory(trusted);

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

@Test
public void checkSettings_shouldRegisterHttpsSchemeWithRegistry() throws Exception {
  configureHttpResponses(UNAUTHORIZED_401_RESPONSE, OK_200_RESPONSE);
  webDavStore.checkSettings();
  ArgumentCaptor<Scheme> schemeCaptor = ArgumentCaptor.forClass(Scheme.class);
  verify(mockSchemeRegistry).register(schemeCaptor.capture());
  assertEquals("https", schemeCaptor.getValue().getName());
  assertEquals(WebDavSocketFactory.class, schemeCaptor.getValue().getSocketFactory().getClass());
}

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

final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
if (!(schm.getSocketFactory() instanceof LayeredSocketFactory)) {
  throw new IllegalArgumentException
    ("Target scheme (" + schm.getName() +
     ") must have layered socket factory.");
final LayeredSocketFactory lsf = (LayeredSocketFactory) schm.getSocketFactory();
final Socket sock;
try {
  sock = lsf.createSocket
    (conn.getSocket(), target.getHostName(), schm.resolvePort(target.getPort()), true);
} catch (ConnectException ex) {
  throw new HttpHostConnectException(target, ex);

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

final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
final SocketFactory sf = schm.getSocketFactory();
final SocketFactory plain_sf;
final LayeredSocketFactory layered_sf;
    Socket connsock = plain_sf.connectSocket(sock,
      addresses[i].getHostAddress(),
      schm.resolvePort(target.getPort()),
      local, 0, params);
    if (sock != connsock) {
      Socket layeredsock = layered_sf.createSocket(sock,
        target.getHostName(),
        schm.resolvePort(target.getPort()),
        true);
      if (layeredsock != sock) {

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

HttpParams httpParams = new BasicHttpParams();
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
client = new DefaultHttpClient(cm, httpParams);

代码示例来源:origin: Fuzion24/JustTrustMe

public ClientConnectionManager getSCCM() {
  KeyStore trustStore;
  try {
    trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null, null);
    SSLSocketFactory sf = new TrustAllSSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", sf, 443));
    ClientConnectionManager ccm = new SingleClientConnManager(null, registry);
    return ccm;
  } catch (Exception e) {
    return null;
  }
}

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

trustStore = KeyStore.getInstance("BKS");
trustStore.load(clientTruststoreIs, "MyPassword".toCharArray());
System.out.println("Loaded server certificates: " + trustStore.size());
socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, "MyTestPassword2010",
  trustStore, null, null);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
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);
HttpResponse response = sClient.execute(httpGet);
HttpEntity httpEntity = response.getEntity();

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

HttpClient httpclient = new DefaultHttpClient();
// truststore
KeyStore ts = KeyStore.getInstance("JKS", "SUN");
ts.load(PostService.class.getResourceAsStream("/truststore.jks"), "amber%".toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing truststore
if(0 == ts.size()) throw new IOException("Error loading truststore");
// tmf
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
// keystore
KeyStore ks = KeyStore.getInstance("PKCS12", "SunJSSE");
ks.load(PostService.class.getResourceAsStream("/" + certName), certPwd.toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing keystore
if(0 == ks.size()) throw new IOException("Error loading keystore");
// kmf
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, certPwd.toCharArray());
// SSL
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// socket
SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", 8443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
// request
HttpMethod get = new GetMethod("https://localhost:8443/foo");
client.executeMethod(get);
IOUtils.copy(get.getResponseBodyAsStream(), System.out);

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

KeyStore trustStore  = KeyStore.getInstance( "BKS" /*KeyStore.getDefaultType()*/ );
FileInputStream instream = new FileInputStream(new File("/mnt/sdcard/keystore.bks"));
try {
  trustStore.load(instream, "222222".toCharArray());
} catch (NoSuchAlgorithmException e) {
  e.printStackTrace();
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);

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

registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
try {
  KeyStore trusted = KeyStore.getInstance("BKS");
    trusted.load(in, "aglite".toCharArray());
  } finally {
    in.close();
  SSLSocketFactory sf = new SSLSocketFactory(trusted);

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

KeyStore keystore  = KeyStore.getInstance("jks");
char[] pwd = "nopassword".toCharArray();
keystore.load(url.openStream(), pwd);
try {
  DefaultHttpClient httpclient = new DefaultHttpClient();
  TrustStrategy trustStrategy = new TrustStrategy() {
  SSLSocketFactory sslsf = new SSLSocketFactory("TLS", null, null, keystore, null,
      trustStrategy, new AllowAllHostnameVerifier());
  Scheme https = new Scheme("https", 443, sslsf);
  httpclient.getConnectionManager().getSchemeRegistry().register(https);
  HttpResponse response1 = httpclient.execute(target1, httpget1);
  System.err.println(response1.getStatusLine());
  HttpEntity entity1 = response1.getEntity();

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

public Socket createSocket(Socket socket, String host, int port,
    boolean autoClose) throws IOException, UnknownHostException {
  return sslContext.getSocketFactory().createSocket(socket, host, port,
      autoClose);
      new SecureRandom());
  HttpClient client = new DefaultHttpClient();
  ClientConnectionManager ccm = client.getConnectionManager();
  SchemeRegistry sr = ccm.getSchemeRegistry();
  sr.register(new Scheme("https", ssf, 443));
  DefaultHttpClient sslClient = new DefaultHttpClient(ccm,
      client.getParams());
  HttpResponse response = sslClient.execute(get);

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

SchemeRegistry schemeRegistry = new SchemeRegistry();
int port = Integer.parseInt(pumMetadata.getProperty(PersistenceProperties.KUNDERA_PORT));
String host = pumMetadata.getProperty(PersistenceProperties.KUNDERA_NODES);
String password = pumMetadata.getProperty(PersistenceProperties.KUNDERA_PASSWORD);
schemeRegistry.register(new Scheme("http", port, ssf));
PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(ccm);
  ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor()
  ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor()

代码示例来源:origin: rnewson/couchdb-lucene

public static synchronized HttpClient getInstance() throws MalformedURLException {
  if (instance == null) {
    final HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1000));
    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry
        .register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 5984));
    schemeRegistry
        .register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    final ClientConnectionManager cm = new ShieldedClientConnManager(
        new ThreadSafeClientConnManager(params, schemeRegistry));
    instance = new DefaultHttpClient(cm, params);
      instance.setCredentialsProvider(credsProvider);
      instance.addRequestInterceptor(new PreemptiveAuthenticationRequestInterceptor(), 0);

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

@Override
protected ClientConnectionManager createClientConnectionManager() {
  SchemeRegistry registry = new SchemeRegistry();
  registry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  registry.register(
      new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
  HttpParams params = getParams();
    connManager = factory.newInstance(params, registry);
  } else {
    connManager = new SingleClientConnManager(getParams(), registry);

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

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

代码示例来源:origin: aws-amplify/aws-sdk-android

final HttpParams httpClientParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpClientParams, config.getConnectionTimeout());
HttpConnectionParams.setSoTimeout(httpClientParams, config.getSocketTimeout());
final Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT);
final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
final Scheme https = new Scheme("https", sslSocketFactory, HTTPS_PORT);
final SchemeRegistry sr = connectionManager.getSchemeRegistry();
sr.register(http);
sr.register(https);

代码示例来源:origin: aws-amplify/aws-sdk-android

public static ThreadSafeClientConnManager createThreadSafeClientConnManager(
      ClientConfiguration config, HttpParams httpClientParams) {
    ConnManagerParams.setMaxConnectionsPerRoute(httpClientParams,
        new ConnPerRouteBean(config.getMaxConnections()));
    ConnManagerParams.setMaxTotalConnections(httpClientParams, config.getMaxConnections());

    SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), DEFAULT_HTTP_PORT));
    registry.register(new Scheme("https", sslSocketFactory, DEFAULT_HTTPS_PORT));

    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
        httpClientParams, registry);
    if (config.useReaper()) {
      IdleConnectionReaper.registerConnectionManager(connectionManager);
    }
    return connectionManager;
  }
}

相关文章