本文整理汇总了Java中org.apache.http.conn.ClientConnectionManager.getSchemeRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java ClientConnectionManager.getSchemeRegistry方法的具体用法?Java ClientConnectionManager.getSchemeRegistry怎么用?Java ClientConnectionManager.getSchemeRegistry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.conn.ClientConnectionManager
的用法示例。
在下文中一共展示了ClientConnectionManager.getSchemeRegistry方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTrustAllHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入方法依赖的package包/类
private static HttpClient getTrustAllHttpClient()
{
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManager[] temp =new TrustManager[1];
temp[0]=new CxfClientUtilsOld.TrustAllManager();
sslContext.init(null, temp, null);
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpClient httpClient=new DefaultHttpClient();
ClientConnectionManager connectionManager = httpClient.getConnectionManager();
SchemeRegistry schemeRegistry = connectionManager.getSchemeRegistry();
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
return(new DefaultHttpClient(connectionManager, httpClient.getParams()));
} catch (Exception e) {
logger.error("Unexpected error", e);
return(null);
}
}
示例2: createThreadSafeClient
import org.apache.http.conn.ClientConnectionManager; //导入方法依赖的package包/类
private static void createThreadSafeClient(boolean forceSecure) {
httpClient = new DefaultHttpClient();
ClientConnectionManager mgr = httpClient.getConnectionManager();
HttpParams params = httpClient.getParams();
SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();
if (forceSecure) {
schemeRegistry.register(new Scheme("https",
getSecureConnectionSetting(), 443));
} else {
HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SSLSocketFactory socketFactory = SSLSocketFactory
.getSocketFactory();
socketFactory
.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
schemeRegistry.register(new Scheme("https", socketFactory, 443));
}
httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params,
schemeRegistry), params);
}
示例3: initHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入方法依赖的package包/类
/**
* 微信自定义信任管理器X509TrustManager
* @param httpclient
* @return
*/
private static HttpClient initHttpClient(HttpClient httpclient) {
try {
TrustManager[] tm = { new MyX509TrustManager() };
// 取得SSL的SSLContext实例
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
// 初始化SSLContext
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SocketFactory ssf = (SocketFactory) sslContext.getSocketFactory();
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 8443));
HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
httpclient = new DefaultHttpClient(ccm, params);
} catch (Exception ex) {
Exceptions.printException(ex);
}
return httpclient;
}
示例4: sendGet
import org.apache.http.conn.ClientConnectionManager; //导入方法依赖的package包/类
/**
* 带参数的GET请求
*
* @param url
* 请求地址
* @param pm
* 参数
* @return
*/
public static String sendGet(String url, BDHttpParam pm) {
// 设置通用参数
StringBuilder params = new StringBuilder();
if (pm.hasCommon()) {
params.append(url).append("?");
for (Entry<String, String> apm : pm.getCommonParams().entrySet()) {
params.append(apm.getKey()).append("=").append(apm.getValue()).append("&");
}
url = params.substring(0, params.lastIndexOf("&"));
}
// 修改适应https请求 @20160804
// HttpClient client = HttpClientBuilder.create().build();
HttpClient client = isHttps(url) ? new DefaultHttpClient() : HttpClientBuilder.create().build();
try {
if (isHttps(url)) {
SSLContext sslCtx = SSLContext.getInstance("SSL");
sslCtx.init(null, new TrustManager[] { X509_TM }, null);
SSLSocketFactory sslSf = new SSLSocketFactory(sslCtx);
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, sslSf));
}
HttpGet get = new HttpGet(url);
log.debug("get url {}", url);
// 设置Cookie
if (pm.hasCookie()) {
StringBuilder cookies = new StringBuilder();
for (Entry<String, String> acm : pm.getCookieParams().entrySet()) {
cookies.append(acm.getKey()).append("=").append(acm.getValue()).append(";");
}
get.setHeader("Cookie", cookies.toString());
log.debug("\twith cookie {}", cookies.toString());
}
// 设置指定http-头
if (pm.hasHeader()) {
for (Entry<String, String> ahm : pm.getHeaderParams().entrySet()) {
get.setHeader(ahm.getKey(), ahm.getValue());
log.debug("\twith header {}={}", ahm.getKey(), ahm.getValue());
}
}
HttpResponse res = client.execute(get);
int code = res.getStatusLine().getStatusCode();
if (code == 200) {
// 判断是否gzip响应 @20160804
Header hd = res.getLastHeader("Content-Encoding");
if (hd != null && hd.getValue().equals("gzip")) {
res.setEntity(new GzipDecompressingEntity(res.getEntity()));
}
return EntityUtils.toString(res.getEntity(), pm.getCharset()).trim();
}
// NetMonitor.log(code, url);
} catch (Exception e) {
// NetMonitor.log(e, url);
} finally {
HttpClientUtils.closeQuietly(client);
}
return "";
}