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


Java SocketFactory类代码示例

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


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

示例1: setup

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

示例2: setup

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

示例3: initHttpClient

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

示例4: createHttpClient

import org.apache.http.conn.scheme.SocketFactory; //导入依赖的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.SocketFactory; //导入依赖的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.SocketFactory; //导入依赖的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.SocketFactory; //导入依赖的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: GoogleHttpClient

import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
private GoogleHttpClient(Context paramContext, String paramString, boolean paramBoolean)
{
  String str1 = paramString + " (" + Build.DEVICE + " " + Build.ID + ")";
  this.mClient = AndroidHttpClient.newInstance(str1 + "; gzip", paramContext);
  this.mCookieSourceApplier = new CookieSourceApplier(this.mClient, null, (byte)0);
  this.mResolver = paramContext.getContentResolver();
  this.mAppName = paramString;
  SchemeRegistry localSchemeRegistry = getConnectionManager().getSchemeRegistry();
  Iterator localIterator = localSchemeRegistry.getSchemeNames().iterator();
  if (localIterator.hasNext())
  {
    String str2 = (String)localIterator.next();
    Scheme localScheme = localSchemeRegistry.unregister(str2);
    SocketFactory localSocketFactory = localScheme.getSocketFactory();
    if ((localSocketFactory instanceof LayeredSocketFactory)) {}
    for (Object localObject = new WrappedLayeredSocketFactory((LayeredSocketFactory)localSocketFactory, (byte)0);; localObject = new WrappedSocketFactory(localSocketFactory, (byte)0))
    {
      localSchemeRegistry.register(new Scheme(str2, (SocketFactory)localObject, localScheme.getDefaultPort()));
      break;
    }
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:23,代码来源:GoogleHttpClient.java

示例9: createDefaultHttpClient

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

示例10: createHttpClient

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

示例11: createHttpClient

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

示例12: getSSLHttpClient

import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
private HttpClient getSSLHttpClient() throws Throwable {
    KeyStore instance = KeyStore.getInstance(KeyStore.getDefaultType());
    instance.load(null, null);
    SocketFactory sSLSocketFactoryEx = new SSLSocketFactoryEx(instance);
    sSLSocketFactoryEx.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme(b.a, sSLSocketFactoryEx, WebSocket.DEFAULT_WSS_PORT));
    return new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams,
            schemeRegistry), basicHttpParams);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:NetworkHelper.java

示例13: a

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

示例14: FlowzrSyncTask

import org.apache.http.conn.scheme.SocketFactory; //导入依赖的package包/类
public FlowzrSyncTask(Context context) {
	this.context=context;
	
	BasicHttpParams params = new BasicHttpParams();
	SchemeRegistry schemeRegistry = new SchemeRegistry();
	schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
	final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
	schemeRegistry.register(new Scheme("https", (SocketFactory) sslSocketFactory, 443));
	ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
	this.http_client = new DefaultHttpClient(cm, params);
	this.dba=new DatabaseAdapter(context);
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:13,代码来源:FlowzrSyncTask.java

示例15: createHttpClient

import org.apache.http.conn.scheme.SocketFactory; //导入依赖的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.SocketFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。