本文整理汇总了Java中org.apache.http.conn.ClientConnectionManager类的典型用法代码示例。如果您正苦于以下问题:Java ClientConnectionManager类的具体用法?Java ClientConnectionManager怎么用?Java ClientConnectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientConnectionManager类属于org.apache.http.conn包,在下文中一共展示了ClientConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNewHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例2: getNewHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例3: a
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
public static b a(String str) {
HttpParams basicHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
HttpClientParams.setRedirecting(basicHttpParams, true);
HttpClientParams.setAuthenticating(basicHttpParams, false);
HttpProtocolParams.setUserAgent(basicHttpParams, str);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
ConnManagerParams.setTimeout(basicHttpParams, 60000);
ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
Security.setProperty("networkaddress.cache.ttl", "-1");
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
return new b(threadSafeClientConnManager, basicHttpParams);
}
示例4: run
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
public void run() {
try {
while (!shutdown) {
synchronized (this) {
wait(1000);
for (ClientConnectionManager connectionManager : connectionManagers) {
connectionManager.closeExpiredConnections();
// TODO constant
connectionManager.closeIdleConnections(30, TimeUnit.SECONDS);
}
}
}
} catch (InterruptedException ex) {
shutdown();
}
}
示例5: getHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
public synchronized static DefaultHttpClient getHttpClient() {
try {
HttpParams params = new BasicHttpParams();
// 设置一些基本参数
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
// 超时设置
// 从连接池中取连接的超时时间
ConnManagerParams.setTimeout(params, 10000); // 连接超时
HttpConnectionParams.setConnectionTimeout(params, 10000); // 请求超时
HttpConnectionParams.setSoTimeout(params, 30000);
SchemeRegistry registry = new SchemeRegistry();
Scheme sch1 = new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80);
registry.register(sch1);
// 使用线程安全的连接管理来创建HttpClient
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
params, registry);
mHttpClient = new DefaultHttpClient(conMgr, params);
} catch (Exception e) {
e.printStackTrace();
}
return mHttpClient;
}
示例6: DefaultRequestDirector
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
@Deprecated
public DefaultRequestDirector(
final HttpRequestExecutor requestExec,
final ClientConnectionManager conman,
final ConnectionReuseStrategy reustrat,
final ConnectionKeepAliveStrategy kastrat,
final HttpRoutePlanner rouplan,
final HttpProcessor httpProcessor,
final HttpRequestRetryHandler retryHandler,
final RedirectHandler redirectHandler,
final AuthenticationHandler targetAuthHandler,
final AuthenticationHandler proxyAuthHandler,
final UserTokenHandler userTokenHandler,
final HttpParams params) {
this(LogFactory.getLog(DefaultRequestDirector.class),
requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
new DefaultRedirectStrategyAdaptor(redirectHandler),
new AuthenticationStrategyAdaptor(targetAuthHandler),
new AuthenticationStrategyAdaptor(proxyAuthHandler),
userTokenHandler,
params);
}
示例7: ManagedClientConnectionImpl
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
ManagedClientConnectionImpl(
final ClientConnectionManager manager,
final ClientConnectionOperator operator,
final HttpPoolEntry entry) {
super();
if (manager == null) {
throw new IllegalArgumentException("Connection manager may not be null");
}
if (operator == null) {
throw new IllegalArgumentException("Connection operator may not be null");
}
if (entry == null) {
throw new IllegalArgumentException("HTTP pool entry may not be null");
}
this.manager = manager;
this.operator = operator;
this.poolEntry = entry;
this.reusable = false;
this.duration = Long.MAX_VALUE;
}
示例8: getNewHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例9: getNewHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
/**
* Gets getUrl DefaultHttpClient which trusts getUrl set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
示例10: createHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
private DefaultHttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpConnectionParams.setConnectionTimeout(params,
CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSoTimeout(params, CONNETED_TIMEOUT * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setMaxTotalConnections(params, 4);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
schReg.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connMgr = new ThreadSafeClientConnManager(
params, schReg);
return new DefaultHttpClient(connMgr, params);
}
示例11: 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);
}
}
示例12: 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);
}
示例13: 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;
}
示例14: newInstance
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
/**
* 创建http client实例
*/
public static HttpClient newInstance(HttpParams params) {
if (!client.containsKey(params)) {
// Create and initialize scheme registry
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// Create an HttpClient with the ThreadSafeClientConnManager.
// This connection manager must be used if more than one thread will
// be using the HttpClient.
// HttpHost proxy = new HttpHost("localhost", 8888);
// params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
DefaultHttpClient c = new HTTPUtil.DefaultHttpClientEx(cm, params);
//put into client
client.put(params, c);
}
return client.get(params);
}
示例15: createHttpClient
import org.apache.http.conn.ClientConnectionManager; //导入依赖的package包/类
/**
* Create a thread-safe client. This client does not do redirecting, to allow us to capture
* correct "error" codes.
*
* @return HttpClient
*/
public static final DefaultHttpClient createHttpClient() {
// Sets up the http part of the service.
final SchemeRegistry supportedSchemes = new SchemeRegistry();
// Register the "http" protocol scheme, it is required
// by the default operator to look up socket factories.
final SocketFactory sf = PlainSocketFactory.getSocketFactory();
supportedSchemes.register(new Scheme("http", sf, 80));
supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// Set some client http client parameter defaults.
final HttpParams httpParams = createHttpParams();
HttpClientParams.setRedirecting(httpParams, false);
final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
supportedSchemes);
return new DefaultHttpClient(ccm, httpParams);
}