當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientConnectionManager類代碼示例

本文整理匯總了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(); 
   } 
}
 
開發者ID:gyqGitHub,項目名稱:WeiXinPayDemo,代碼行數:24,代碼來源:Util.java

示例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(); 
   } 
}
 
開發者ID:cheng2016,項目名稱:developNote,代碼行數:24,代碼來源:HttpUtil.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:b.java

示例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();
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:17,代碼來源:RestProtocol.java

示例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;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:24,代碼來源:MyHtttpClient.java

示例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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:DefaultRequestDirector.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:ManagedClientConnectionImpl.java

示例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();
    }
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:26,代碼來源:MySSLSocketFactory.java

示例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();
    }
}
 
開發者ID:yiwent,項目名稱:Mobike,代碼行數:26,代碼來源:MySSLSocketFactory.java

示例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);
}
 
開發者ID:iQuick,項目名稱:NewsMe,代碼行數:23,代碼來源:M3u8ContentParser.java

示例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);
       }
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:22,代碼來源:SendingUtils.java

示例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);
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-follow-up,代碼行數:22,代碼來源:OdooSafeClient.java

示例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;
   }
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:31,代碼來源:HttpRequestUtil.java

示例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);
}
 
開發者ID:gmud,項目名稱:bbsbrowser_android,代碼行數:24,代碼來源:HTTPUtil.java

示例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);
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:25,代碼來源:AbstractHttpApi.java


注:本文中的org.apache.http.conn.ClientConnectionManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。