本文整理汇总了Java中ch.boye.httpclientandroidlib.conn.scheme.Scheme类的典型用法代码示例。如果您正苦于以下问题:Java Scheme类的具体用法?Java Scheme怎么用?Java Scheme使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Scheme类属于ch.boye.httpclientandroidlib.conn.scheme包,在下文中一共展示了Scheme类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSecureConnection
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
public void updateSecureConnection(
final OperatedClientConnection conn,
final HttpHost target,
final HttpContext context,
final HttpParams params) throws IOException {
Args.notNull(conn, "Connection");
Args.notNull(target, "Target host");
Args.notNull(params, "Parameters");
Asserts.check(conn.isOpen(), "Connection must be open");
final SchemeRegistry registry = getSchemeRegistry(context);
final Scheme schm = registry.getScheme(target.getSchemeName());
Asserts.check(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory,
"Socket factory must implement SchemeLayeredSocketFactory");
final SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
final Socket sock = lsf.createLayeredSocket(
conn.getSocket(), target.getHostName(), schm.resolvePort(target.getPort()), params);
prepareSocket(sock, context, params);
conn.update(sock, target, lsf.isSecure(sock), params);
}
示例2: enableTLSConnectionManager
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
private static ClientConnectionManager enableTLSConnectionManager() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, new SecureRandom());
Logger.debug(LOG_TAG, "Using protocols and cipher suites for Android API " + android.os.Build.VERSION.SDK_INT);
SSLSocketFactory sf = new SSLSocketFactory(sslContext, GlobalConstants.DEFAULT_PROTOCOLS, GlobalConstants.DEFAULT_CIPHER_SUITES, null);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", 443, sf));
schemeRegistry.register(new Scheme("http", 80, new PlainSocketFactory()));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
cm.setMaxTotal(MAX_TOTAL_CONNECTIONS);
cm.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
connManager = cm;
return cm;
}
示例3: wrapClient
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
public static AbstractHttpClient wrapClient(HttpClient base) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509AlwaysTrust();
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new ch.boye.httpclientandroidlib.conn.ssl.SSLSocketFactory(
ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = base.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
return new DefaultHttpClient(ccm, base.getParams());
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
示例4: createConnectRequest
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
/**
* Creates the CONNECT request for tunnelling.
* Called by {@link #createTunnelToTarget createTunnelToTarget}.
*
* @param route the route to establish
* @param context the context for request execution
*
* @return the CONNECT request for tunnelling
*/
protected HttpRequest createConnectRequest(final HttpRoute route,
final HttpContext context) {
// see RFC 2817, section 5.2 and
// INTERNET-DRAFT: Tunneling TCP based protocols through
// Web proxy servers
final HttpHost target = route.getTargetHost();
final String host = target.getHostName();
int port = target.getPort();
if (port < 0) {
final Scheme scheme = connManager.getSchemeRegistry().
getScheme(target.getSchemeName());
port = scheme.getDefaultPort();
}
final StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host);
buffer.append(':');
buffer.append(Integer.toString(port));
final String authority = buffer.toString();
final ProtocolVersion ver = HttpProtocolParams.getVersion(params);
final HttpRequest req = new BasicHttpRequest
("CONNECT", authority, ver);
return req;
}
示例5: determineRoute
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
public HttpRoute determineRoute(final HttpHost target,
final HttpRequest request,
final HttpContext context)
throws HttpException {
Args.notNull(request, "HTTP request");
// If we have a forced route, we can do without a target.
HttpRoute route =
ConnRouteParams.getForcedRoute(request.getParams());
if (route != null) {
return route;
}
// If we get here, there is no forced route.
// So we need a target to compute a route.
Asserts.notNull(target, "Target host");
final InetAddress local =
ConnRouteParams.getLocalAddress(request.getParams());
final HttpHost proxy = determineProxy(target, request, context);
final Scheme schm =
this.schemeRegistry.getScheme(target.getSchemeName());
// as it is typically used for TLS/SSL, we assume that
// a layered scheme implies a secure connection
final boolean secure = schm.isLayered();
if (proxy == null) {
route = new HttpRoute(target, local, secure);
} else {
route = new HttpRoute(target, local, proxy, secure);
}
return route;
}
示例6: createDefault
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
/**
* Initializes default scheme registry based on JSSE defaults. System properties will
* not be taken into consideration.
*/
public static SchemeRegistry createDefault() {
final SchemeRegistry registry = new SchemeRegistry();
registry.register(
new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(
new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
return registry;
}
示例7: createDefaultSchemeRegistry
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
/**
* Creates a new {@link org.apache.http.conn.scheme.SchemeRegistry} for
* default ports with socket factories.
*
* @return a new {@link org.apache.http.conn.scheme.SchemeRegistry}.
*/
protected SchemeRegistry createDefaultSchemeRegistry() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", this.createDefaultSocketFactory(),
80));
registry.register(new Scheme("https", this
.createDefaultSecureSocketFactory(), 443));
return registry;
}
示例8: init
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
private void init() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
ClientConnectionManager cm = new PoolingClientConnectionManager(registry);
mClient = new DefaultHttpClient(cm);
}
示例9: determineRoute
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
public HttpRoute determineRoute(final HttpHost target,
final HttpRequest request,
final HttpContext context)
throws HttpException {
Args.notNull(request, "HTTP request");
// If we have a forced route, we can do without a target.
HttpRoute route =
ConnRouteParams.getForcedRoute(request.getParams());
if (route != null) {
return route;
}
// If we get here, there is no forced route.
// So we need a target to compute a route.
Asserts.notNull(target, "Target host");
final InetAddress local =
ConnRouteParams.getLocalAddress(request.getParams());
final HttpHost proxy =
ConnRouteParams.getDefaultProxy(request.getParams());
final Scheme schm;
try {
schm = this.schemeRegistry.getScheme(target.getSchemeName());
} catch (final IllegalStateException ex) {
throw new HttpException(ex.getMessage());
}
// as it is typically used for TLS/SSL, we assume that
// a layered scheme implies a secure connection
final boolean secure = schm.isLayered();
if (proxy == null) {
route = new HttpRoute(target, local, secure);
} else {
route = new HttpRoute(target, local, proxy, secure);
}
return route;
}
示例10: createSystemDefault
import ch.boye.httpclientandroidlib.conn.scheme.Scheme; //导入依赖的package包/类
/**
* Initializes default scheme registry using system properties as described in
* <a href="http://download.oracle.com/javase/1,5.0/docs/guide/security/jsse/JSSERefGuide.html">
* "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform
* Standard Edition 5</a>
* <p>
* The following system properties are taken into account by this method:
* <ul>
* <li>ssl.TrustManagerFactory.algorithm</li>
* <li>javax.net.ssl.trustStoreType</li>
* <li>javax.net.ssl.trustStore</li>
* <li>javax.net.ssl.trustStoreProvider</li>
* <li>javax.net.ssl.trustStorePassword</li>
* <li>java.home</li>
* <li>ssl.KeyManagerFactory.algorithm</li>
* <li>javax.net.ssl.keyStoreType</li>
* <li>javax.net.ssl.keyStore</li>
* <li>javax.net.ssl.keyStoreProvider</li>
* <li>javax.net.ssl.keyStorePassword</li>
* </ul>
* <p>
*
* @since 4.2
*/
public static SchemeRegistry createSystemDefault() {
final SchemeRegistry registry = new SchemeRegistry();
registry.register(
new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(
new Scheme("https", 443, SSLSocketFactory.getSystemSocketFactory()));
return registry;
}