本文整理匯總了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 "";
}