Java 类org.apache.http.conn.scheme.SocketFactory 实例源码

项目:PhET    文件:ManagerConnectProxy.java   
/**
 * 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;

}
项目:PhET    文件:ManagerConnectDirect.java   
/**
 * 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;

}
项目:simbest-cores    文件:HttpRequestUtil.java   
/**
 * 微信自定义信任管理器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;
   }
项目:foursquared    文件:AbstractHttpApi.java   
/**
 * 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);
}
项目:foursquared    文件:RemoteResourceFetcher.java   
/**
 * 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);
}
项目:foursquared.eclair    文件:AbstractHttpApi.java   
/**
 * 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);
}
项目:foursquared.eclair    文件:RemoteResourceFetcher.java   
/**
 * 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);
}
项目:eshow-android    文件:AbHttpClient.java   
/**
 * 获取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;
}
项目:FMTech    文件:GoogleHttpClient.java   
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;
    }
  }
}
项目:dataasync    文件:HttpHandler.java   
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);
    }
}
项目:androidsummary    文件:AbHttpClient.java   
/**
 * 获取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;
}
项目:lightDroid    文件:AbstractHttpApi.java   
/**
 * 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);
}
项目:cJUnit-mc626    文件:ManagerConnectProxy.java   
/**
 * 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;

}
项目:cJUnit-mc626    文件:ManagerConnectDirect.java   
/**
 * 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;

}
项目:boohee_v5.6    文件:NetworkHelper.java   
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);
}
项目:boohee_v5.6    文件:b.java   
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;
}
项目:financisto1-holo    文件:FlowzrSyncTask.java   
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);
}
项目:aos-MediaLib    文件:NetworkResourceLoader.java   
/**
 * 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;
}
项目:GOpenSource_AppKit_Android_AS    文件:TrustAllSSLSocketFactory.java   
public static SocketFactory getDefault() {
  if (instance == null) {
    try {
      instance = new TrustAllSSLSocketFactory();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  return instance;
}
项目:GizOpenSource_AppKit_Android    文件:TrustAllSSLSocketFactory.java   
public static SocketFactory getDefault() {
  if (instance == null) {
    try {
      instance = new TrustAllSSLSocketFactory();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  return instance;
}
项目:Gizwits-SmartBuld_Android    文件:TrustAllSSLSocketFactory.java   
public static SocketFactory getDefault() {
  if (instance == null) {
    try {
      instance = new TrustAllSSLSocketFactory();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  return instance;
}
项目:gaeproxy    文件:WeaveTransport.java   
private static SocketFactory createSocketFactory(boolean allowInvalidCerts) {
    SocketFactory sslSocketFactory;
    if (allowInvalidCerts) {
        sslSocketFactory = new WeaveSSLSocketFactory();
    } else {
        sslSocketFactory = SSLSocketFactory.getSocketFactory();
        ((SSLSocketFactory) sslSocketFactory)
                .setHostnameVerifier(new WeaveHostnameVerifier());
    }
    return sslSocketFactory;
}
项目:Popeens-DSub    文件:KakaduaUtil.java   
private static SocketFactory createSSLSocketFactory() {
    try {
        return new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } catch (Throwable x) {
        Log.e("TAG", "Failed to create custom SSL socket factory, using default.", x);
        return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
    }
}
项目:zirco-browser    文件:WeaveTransport.java   
private static SocketFactory createSocketFactory(boolean allowInvalidCerts) {
  SocketFactory sslSocketFactory;
  if (allowInvalidCerts) {
    sslSocketFactory = new WeaveSSLSocketFactory();
  } else {
    sslSocketFactory = SSLSocketFactory.getSocketFactory();
    ((SSLSocketFactory)sslSocketFactory).setHostnameVerifier(new WeaveHostnameVerifier());
  }
  return sslSocketFactory;
}
项目:madsonic-5.5    文件:RESTMusicService.java   
private SocketFactory createSSLSocketFactory() {
    try {
        return new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } catch (Throwable x) {
        LOG.error("Failed to create custom SSL socket factory, using default.", x);
        return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
    }
}
项目:madsonic-5.6    文件:RESTMusicService.java   
private SocketFactory createSSLSocketFactory() {
    try {
        return new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } catch (Throwable x) {
        LOG.error("Failed to create custom SSL socket factory, using default.", x);
        return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
    }
}
项目:haavi    文件:HttpClientProvider.java   
public SocketFactory getHttpsSocketFactory() {
    try {
        final Class<?> sessionCacheClass = Class.forName("android.net.SSLSessionCache");
        final Object sessionCache = sessionCacheClass.getConstructor(Context.class).newInstance(application);
        final Method getHttpSocketFactory = Class.forName("android.net.SSLCertificateSocketFactory")
                                                 .getMethod("getHttpSocketFactory", int.class, sessionCacheClass);
        return (SocketFactory) getHttpSocketFactory.invoke(null, CONNECTION_TIMEOUT, sessionCache);
    } catch (Exception e) {
        Log.e("HttpClientProvider", "Can't create https socket factory", e);
    }
    return null;
}
项目:ZircoBrowser    文件:WeaveTransport.java   
private static SocketFactory createSocketFactory(boolean allowInvalidCerts) {
  SocketFactory sslSocketFactory;
  if (allowInvalidCerts) {
    sslSocketFactory = new WeaveSSLSocketFactory();
  } else {
    sslSocketFactory = SSLSocketFactory.getSocketFactory();
    ((SSLSocketFactory)sslSocketFactory).setHostnameVerifier(new WeaveHostnameVerifier());
  }
  return sslSocketFactory;
}
项目:gokit-android    文件:TrustAllSSLSocketFactory.java   
public static SocketFactory getDefault() {
  if (instance == null) {
    try {
      instance = new TrustAllSSLSocketFactory();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  return instance;
}
项目:galaxy-fds-sdk-android    文件:GalaxyFDSClientImpl.java   
private HttpClient createHttpClient(FDSClientConfiguration config) {
      /* Set HTTP client parameters */
  HttpParams httpClientParams = new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpClientParams,
      config.getConnectionTimeoutMs());
  HttpConnectionParams.setSoTimeout(httpClientParams,
      config.getSocketTimeoutMs());
  HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true);
  HttpConnectionParams.setTcpNoDelay(httpClientParams, true);

  int socketSendBufferSizeHint = config.getSocketBufferSizeHints()[0];
  int socketReceiveBufferSizeHint = config.getSocketBufferSizeHints()[1];
  if (socketSendBufferSizeHint > 0 || socketReceiveBufferSizeHint > 0) {
    HttpConnectionParams.setSocketBufferSize(httpClientParams,
        Math.max(socketSendBufferSizeHint, socketReceiveBufferSizeHint));
  }

  SchemeRegistry registry = new SchemeRegistry();
  SocketFactory socketFactory = PlainSocketFactory.getSocketFactory();
  registry.register(new Scheme(HTTP_SCHEME, socketFactory, 80));

  if (config.isHttpsEnabled()) {
    SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(
        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(HTTPS_SCHEME, sslSocketFactory, 443));
  }

  ThreadSafeClientConnManager connectionManager =
      new ThreadSafeClientConnManager(httpClientParams, registry);
  DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager,
      httpClientParams);
  return httpClient;
}
项目:madsonic-5.5    文件:RESTMusicService.java   
private SocketFactory createSSLSocketFactory() {
    try {
        return new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } catch (Throwable x) {
        LOG.error("Failed to create custom SSL socket factory, using default.", x);
        return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
    }
}
项目:ZicroBrowser    文件:WeaveTransport.java   
private static SocketFactory createSocketFactory(boolean allowInvalidCerts) {
  SocketFactory sslSocketFactory;
  if (allowInvalidCerts) {
    sslSocketFactory = new WeaveSSLSocketFactory();
  } else {
    sslSocketFactory = SSLSocketFactory.getSocketFactory();
    ((SSLSocketFactory)sslSocketFactory).setHostnameVerifier(new WeaveHostnameVerifier());
  }
  return sslSocketFactory;
}
项目:xface-android    文件:XSSLSocketFactory.java   
public static SocketFactory getSocketFactory() {
    if (instance == null) {
        if (XSSLManager.getInstace().getSslContext() == null) {
            instance = SSLSocketFactory.getSocketFactory();
        } else {
            instance = new XSSLSocketFactory();
        }
    }
    return instance;
}
项目:openxface-android    文件:XSSLSocketFactory.java   
public static SocketFactory getSocketFactory() {
    if (instance == null) {
        if (XSSLManager.getInstace().getSslContext() == null) {
            instance = SSLSocketFactory.getSocketFactory();
        } else {
            instance = new XSSLSocketFactory();
        }
    }
    return instance;
}
项目:Onosendai    文件:HttpClientFactory.java   
private static void addHttpsSchemaForTrustStore (final ClientConnectionManager connMan, final String tsPath, final char[] password) throws IOException, GeneralSecurityException {
    final KeyStore truststore = loadKeyStore(tsPath, password);

    final TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmfactory.init(truststore);
    final SocketFactory sf = new TlsSniSocketFactory(tmfactory.getTrustManagers());

    final Scheme scheme = new Scheme("https", sf, 443); // NOSONAR 443 is not a magic number.  Its HTTPS specification.
    connMan.getSchemeRegistry().register(scheme);
}
项目:buddycloud-android    文件:BuddycloudHTTPHelper.java   
public static HttpClient createHttpClient(Context context) {
    try {

        SchemeRegistry registry = new SchemeRegistry();
        SocketFactory socketFactory = createSecureSocketFactory();

        registry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));
        registry.register(new Scheme("https", socketFactory, 443));

        HttpParams connManagerParams = new BasicHttpParams();
        ConnManagerParams.setMaxTotalConnections(connManagerParams, 20);
        ConnManagerParams.setMaxConnectionsPerRoute(connManagerParams,
                new ConnPerRouteBean(20));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(
                connManagerParams, registry);

        DefaultHttpClient client = new DefaultHttpClient(ccm, null);
        client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(
                0, true));

        return client;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:letv    文件:HttpUtils.java   
public static HttpClient getHttpClient(Context context, String str, String str2) {
    OpenConfig instance;
    int i;
    int i2 = 0;
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
    if (VERSION.SDK_INT < 16) {
        try {
            KeyStore instance2 = KeyStore.getInstance(KeyStore.getDefaultType());
            instance2.load(null, null);
            SocketFactory customSSLSocketFactory = new CustomSSLSocketFactory(instance2);
            customSSLSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, customSSLSocketFactory, 443));
        } catch (Exception e) {
            schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, SSLSocketFactory.getSocketFactory(), 443));
        }
    } else {
        schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, SSLSocketFactory.getSocketFactory(), 443));
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    if (context != null) {
        instance = OpenConfig.getInstance(context, str);
    } else {
        instance = null;
    }
    if (instance != null) {
        i = instance.getInt("Common_HttpConnectionTimeout");
        i2 = instance.getInt("Common_SocketConnectionTimeout");
    } else {
        i = 0;
    }
    if (i == 0) {
        i = LetvConstant.WIDGET_UPDATE_UI_TIME;
    }
    if (i2 == 0) {
        i2 = 30000;
    }
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, i);
    HttpConnectionParams.setSoTimeout(basicHttpParams, i2);
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
    HttpProtocolParams.setUserAgent(basicHttpParams, "AndroidSDK_" + VERSION.SDK + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + Build.DEVICE + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + VERSION.RELEASE);
    HttpClient defaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
    NetworkProxy proxy = getProxy(context);
    if (proxy != null) {
        defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost(proxy.host, proxy.port));
    }
    return defaultHttpClient;
}
项目:boohee_v5.6    文件:HttpUtils.java   
public static HttpClient getHttpClient(Context context, String str, String str2) {
    OpenConfig instance;
    int i;
    int i2 = 0;
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    if (VERSION.SDK_INT < 16) {
        try {
            KeyStore instance2 = KeyStore.getInstance(KeyStore.getDefaultType());
            instance2.load(null, null);
            SocketFactory customSSLSocketFactory = new CustomSSLSocketFactory(instance2);
            customSSLSocketFactory.setHostnameVerifier(SSLSocketFactory
                    .STRICT_HOSTNAME_VERIFIER);
            schemeRegistry.register(new Scheme(b.a, customSSLSocketFactory, WebSocket
                    .DEFAULT_WSS_PORT));
        } catch (Exception e) {
            schemeRegistry.register(new Scheme(b.a, SSLSocketFactory.getSocketFactory(),
                    WebSocket.DEFAULT_WSS_PORT));
        }
    } else {
        schemeRegistry.register(new Scheme(b.a, SSLSocketFactory.getSocketFactory(),
                WebSocket.DEFAULT_WSS_PORT));
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    if (context != null) {
        instance = OpenConfig.getInstance(context, str);
    } else {
        instance = null;
    }
    if (instance != null) {
        i = instance.getInt("Common_HttpConnectionTimeout");
        i2 = instance.getInt("Common_SocketConnectionTimeout");
    } else {
        i = 0;
    }
    if (i == 0) {
        i = 15000;
    }
    if (i2 == 0) {
        i2 = 30000;
    }
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, i);
    HttpConnectionParams.setSoTimeout(basicHttpParams, i2);
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(basicHttpParams, "UTF-8");
    HttpProtocolParams.setUserAgent(basicHttpParams, "AndroidSDK_" + VERSION.SDK + "_" +
            Build.DEVICE + "_" + VERSION.RELEASE);
    HttpClient defaultHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager
            (basicHttpParams, schemeRegistry), basicHttpParams);
    NetworkProxy proxy = getProxy(context);
    if (proxy != null) {
        defaultHttpClient.getParams().setParameter("http.route.default-proxy", new HttpHost
                (proxy.host, proxy.port));
    }
    return defaultHttpClient;
}
项目:PhET    文件:OperatorConnectDirect.java   
public static void main(String[] args) throws Exception {
    HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    // some general setup
    // Register the "http" protocol scheme, it is required
    // by the default operator to look up socket factories.
    SchemeRegistry 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);

    // one operator can be used for many connections
    ClientConnectionOperator scop = new DefaultClientConnectionOperator(supportedSchemes);

    HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
    req.addHeader("Host", target.getHostName());

    HttpContext ctx = new BasicHttpContext();

    OperatedClientConnection conn = scop.createConnection();
    try {
        System.out.println("opening connection to " + target);
        scop.openConnection(conn, target, null, ctx, params);
        System.out.println("sending request");
        conn.sendRequestHeader(req);
        // there is no request entity
        conn.flush();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");
    } finally {
        System.out.println("closing connection");
        conn.close();
    }
}
项目:FMTech    文件:GoogleHttpClient.java   
private WrappedSocketFactory(SocketFactory paramSocketFactory)
{
  this.mDelegate = paramSocketFactory;
}