当前位置: 首页>>代码示例>>Java>>正文


Java PlainSocketFactory.getSocketFactory方法代码示例

本文整理汇总了Java中org.apache.http.conn.scheme.PlainSocketFactory.getSocketFactory方法的典型用法代码示例。如果您正苦于以下问题:Java PlainSocketFactory.getSocketFactory方法的具体用法?Java PlainSocketFactory.getSocketFactory怎么用?Java PlainSocketFactory.getSocketFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.conn.scheme.PlainSocketFactory的用法示例。


在下文中一共展示了PlainSocketFactory.getSocketFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的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

示例2: setup

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
/**
 * Performs general setup.
 * This should be called only once.
 */
private final static void setup() {

    // Register the "http" and "https" protocol schemes, they are
    // required by the default operator to look up socket factories.
    supportedSchemes = new SchemeRegistry();
    SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));
    sf = SSLSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("https", sf, 80));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(params, false);
    defaultParameters = params;

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:ManagerConnectProxy.java

示例3: setup

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
/**
 * Performs general setup.
 * This should be called only once.
 */
private final static void setup() {

    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    supportedSchemes = new SchemeRegistry();
    SocketFactory sf = PlainSocketFactory.getSocketFactory();
    supportedSchemes.register(new Scheme("http", sf, 80));

    // Prepare parameters.
    // Since this example doesn't use the full core framework,
    // only few parameters are actually required.
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(params, false);
    defaultParameters = params;

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:ManagerConnectDirect.java

示例4: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的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

示例5: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的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() {
    // Shamelessly cribbed from AndroidHttpClient
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 10 seconds. Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
    HttpConnectionParams.setSoTimeout(params, 10 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // 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));

    final ClientConnectionManager ccm = new ThreadSafeClientConnManager(params,
            supportedSchemes);
    return new DefaultHttpClient(ccm, params);
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:32,代码来源:RemoteResourceFetcher.java

示例6: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的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));

    // 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:vsvankhede,项目名称:foursquared.eclair,代码行数:24,代码来源:AbstractHttpApi.java

示例7: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
/**
 * 获取HttpClient,自签名的证书,如果想做签名参考AuthSSLProtocolSocketFactory类
 * @return
 */
public DefaultHttpClient createHttpClient(){
	BasicHttpParams httpParams = getHttpParams();
	if(mIsOpenEasySSL){
		 // 支持https的   SSL自签名的实现类
	     EasySSLProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
         SchemeRegistry supportedSchemes = new SchemeRegistry();
         SocketFactory socketFactory = PlainSocketFactory.getSocketFactory();
         supportedSchemes.register(new Scheme("http", socketFactory, 80));
         supportedSchemes.register(new Scheme("https",easySSLProtocolSocketFactory, 443));
         //安全的ThreadSafeClientConnManager,否则不能用单例的HttpClient
         ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(
                 httpParams, supportedSchemes);
         //取得HttpClient ThreadSafeClientConnManager
         mHttpClient = new DefaultHttpClient(connectionManager, httpParams);
	}else{
		 //线程安全的HttpClient
		 mHttpClient = new DefaultHttpClient(httpParams);
	}
	//自动重试
	mHttpClient.setHttpRequestRetryHandler(mRequestRetryHandler);
	mHttpClient.setCookieStore(mCookieStore);
  return mHttpClient;
}
 
开发者ID:bangqu,项目名称:eshow-android,代码行数:28,代码来源:AbHttpClient.java

示例8: createDefaultHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
public static DefaultHttpClient createDefaultHttpClient(boolean threadSafe,
		boolean enableRedirect) {
	HttpParams httpParams = new BasicHttpParams();
	HttpClientParams.setRedirecting(httpParams, enableRedirect);
	setTimeout(httpParams, Constants.HTTP_REQUEST_TIME_OUT * 1000);

	if (threadSafe) {
		SchemeRegistry supportedSchemes = new SchemeRegistry();
		SocketFactory sf = PlainSocketFactory.getSocketFactory();
		supportedSchemes.register(new Scheme("http", sf, 80));
		ClientConnectionManager ccm = new ThreadSafeClientConnManager(
				httpParams, supportedSchemes);
		return new DefaultHttpClient(ccm, httpParams);
	} else {
		return new DefaultHttpClient(httpParams);
	}
}
 
开发者ID:coodoing,项目名称:dataasync,代码行数:18,代码来源:HttpHandler.java

示例9: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
/**
 * 获取HttpClient,自签名的证书,如果想做签名参考AuthSSLProtocolSocketFactory类
 * @param httpParams
 * @return
 */
public DefaultHttpClient createHttpClient(){
	BasicHttpParams httpParams = getHttpParams();
	if(mIsOpenEasySSL){
		 // 支持https的   SSL自签名的实现类
	     EasySSLProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
         SchemeRegistry supportedSchemes = new SchemeRegistry();
         SocketFactory socketFactory = PlainSocketFactory.getSocketFactory();
         supportedSchemes.register(new Scheme("http", socketFactory, 80));
         supportedSchemes.register(new Scheme("https",easySSLProtocolSocketFactory, 443));
         //安全的ThreadSafeClientConnManager,否则不能用单例的HttpClient
         ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(
                 httpParams, supportedSchemes);
         //取得HttpClient ThreadSafeClientConnManager
         mHttpClient = new DefaultHttpClient(connectionManager, httpParams);
	}else{
		 //线程安全的HttpClient
		 mHttpClient = new DefaultHttpClient(httpParams);
	}
	//自动重试
	mHttpClient.setHttpRequestRetryHandler(mRequestRetryHandler);
	mHttpClient.setCookieStore(mCookieStore);
  return mHttpClient;
}
 
开发者ID:jingshauizh,项目名称:androidsummary,代码行数:29,代码来源:AbHttpClient.java

示例10: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的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(Context mContext) {
    // 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(mContext);
    HttpClientParams.setRedirecting(httpParams, false);

    final ClientConnectionManager ccm = new ThreadSafeClientConnManager(httpParams,
            supportedSchemes);
    return new DefaultHttpClient(ccm, httpParams);
}
 
开发者ID:elphinkuo,项目名称:lightDroid,代码行数:25,代码来源:AbstractHttpApi.java

示例11: getHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
public synchronized DefaultHttpClient getHttpClient(){
	if(httpClient == null){
		final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
		final PlainSocketFactory plainSocketFactory = PlainSocketFactory.getSocketFactory();
		BasicHttpParams params = new BasicHttpParams();
		SchemeRegistry schemeRegistry = new SchemeRegistry();
		schemeRegistry.register(new Scheme("http", plainSocketFactory, 80));
		schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
		
		HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
		HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
		
		ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
		httpClient = new DefaultHttpClient(manager, params);
	}
	return httpClient;
}
 
开发者ID:Soniy7x,项目名称:Auie,代码行数:18,代码来源:UEHttpClient.java

示例12: getHttpsClientTrustAll

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
public HttpClient getHttpsClientTrustAll() {
    try {
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        }, new AllowAllHostnameVerifier());

        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, sf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
    	log.error("Failed to create TrustAll https client", ex);
        return new DefaultHttpClient();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:22,代码来源:HttpService.java

示例13: getHttpsClientDefaulTrustStore

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
@Deprecated
public HttpClient getHttpsClientDefaulTrustStore() {
    try {
        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SSLContext ctx = SSLContext.getInstance("TLS");
           SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, ssf));

        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);

        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
    	log.error("Failed to create https client", ex);
        return new DefaultHttpClient();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:21,代码来源:HttpService.java

示例14: a

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
public static b a() {
    if (b == null) {
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
        basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
        ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
        ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
        ConnManagerParams.setTimeout(basicHttpParams, 1000);
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
        HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
        HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
        HttpClientParams.setRedirecting(basicHttpParams, true);
        HttpClientParams.setAuthenticating(basicHttpParams, false);
        HttpProtocolParams.setUserAgent(basicHttpParams, a);
        try {
            SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
            socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
            Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(scheme);
            schemeRegistry.register(scheme2);
            b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
        } catch (Exception e) {
            b = new b(basicHttpParams);
        }
    }
    return b;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:32,代码来源:b.java

示例15: createHttpClient

import org.apache.http.conn.scheme.PlainSocketFactory; //导入方法依赖的package包/类
/**
 * Create a thread-safe client. This client does not do redirecting, to allow us to capture
 * correct "error" codes.
 *
 * @return HttpClient
 */
public final DefaultHttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);  
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);  
    HttpProtocolParams.setUseExpectContinue(params, true);  
    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 30 seconds. Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 10*1000);
    HttpConnectionParams.setSoTimeout(params, 20*1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    
    ConnManagerParams.setTimeout(params, 5 * 1000);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(50));
    ConnManagerParams.setMaxTotalConnections(params, 200);
    
    // 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));  
    final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(params,
            supportedSchemes);
    
    DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params);
    
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));
    
    return httpClient;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:42,代码来源:NetworkResourceLoader.java


注:本文中的org.apache.http.conn.scheme.PlainSocketFactory.getSocketFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。