org.apache.http.conn.scheme.PlainSocketFactory Java Examples
The following examples show how to use
org.apache.http.conn.scheme.PlainSocketFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpService.java From oxAuth with MIT License | 7 votes |
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(); } }
Example #2
Source File: Util.java From AppServiceRestFul with GNU General Public License v3.0 | 6 votes |
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(); } }
Example #3
Source File: HttpLoadTestClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public void run() { SchemeRegistry supportedSchemes = new SchemeRegistry(); SocketFactory sf = PlainSocketFactory.getSocketFactory(); supportedSchemes.register(new Scheme("http", sf, 80)); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(supportedSchemes); connManager.setDefaultMaxPerRoute(1000); DefaultHttpClient client = new DefaultHttpClient(connManager); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 30000); HttpConnectionParams.setSoTimeout(params, 30000); client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { public boolean retryRequest(IOException e, int i, HttpContext httpContext) { return false; } }); //test API call long t1 = System.currentTimeMillis(); testEndpoint(client,apiEndpoint); long t2 = System.currentTimeMillis(); timeElapsedForAPICall = t2 - t1; }
Example #4
Source File: MySSLSocketFactory.java From Mobike with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #5
Source File: HttpClientFactory.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static HttpClient getTrustedClient(int httpPort, int httpsPort, File keystore, String keypass) { SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort)); // https scheme schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), httpsPort)); 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); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); return new DispatchHttpClient(keystore, keypass); }
Example #6
Source File: M3u8ContentParser.java From NewsMe with Apache License 2.0 | 6 votes |
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); }
Example #7
Source File: Util.java From AppServiceRestFul with GNU General Public License v3.0 | 6 votes |
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(); } }
Example #8
Source File: WebServiceUtil.java From appinventor-extensions with Apache License 2.0 | 6 votes |
/** * Returns the one <code>WebServiceUtil</code> instance * @return the one <code>WebServiceUtil</code> instance */ public static WebServiceUtil getInstance() { // This needs to be here instead of in the constructor because // it uses classes that are in the AndroidSDK and thus would // cause Stub! errors when running the component descriptor. synchronized(httpClientSynchronizer) { if (httpClient == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicHttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); ConnManagerParams.setMaxTotalConnections(params, 20); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); WebServiceUtil.httpClient = new DefaultHttpClient(manager, params); } } return INSTANCE; }
Example #9
Source File: HttpClientFactory.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static HttpClient getClient(int httpPort, int httpsPort) { SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); 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); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(cm, params); }
Example #10
Source File: MyHtttpClient.java From Huochexing12306 with Apache License 2.0 | 6 votes |
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; }
Example #11
Source File: HttpComponentsHelper.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * prepare for the https connection * call this in the constructor of the class that does the connection if * it's used multiple times */ private void setup() { SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1)); params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf8"); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // set the user credentials for our site "example.com" credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT), new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere")); clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); context = new BasicHttpContext(); context.setAttribute("http.auth.credentials-provider", credentialsProvider); }
Example #12
Source File: PoolingClientConnectionManager.java From letv with Apache License 2.0 | 6 votes |
public static HttpClient get() { HttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, 3000); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30)); ConnManagerParams.setMaxTotalConnections(httpParams, 30); HttpClientParams.setRedirecting(httpParams, true); HttpProtocolParams.setUseExpectContinue(httpParams, true); HttpConnectionParams.setStaleCheckingEnabled(httpParams, false); HttpConnectionParams.setSoTimeout(httpParams, 2000); HttpConnectionParams.setConnectionTimeout(httpParams, 2000); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, 8192); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80)); try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443)); } catch (Exception ex) { ex.printStackTrace(); } return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams); }
Example #13
Source File: DockerClient.java From docker-java with Apache License 2.0 | 6 votes |
private DockerClient(Config config) { restEndpointUrl = config.url + "/v" + config.version; ClientConfig clientConfig = new DefaultClientConfig(); //clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", config.url.getPort(), PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection cm.setMaxTotal(1000); // Increase default max connection per route cm.setDefaultMaxPerRoute(1000); HttpClient httpClient = new DefaultHttpClient(cm); client = new ApacheHttpClient4(new ApacheHttpClient4Handler(httpClient, null, false), clientConfig); client.setReadTimeout(10000); //Experimental support for unix sockets: //client = new UnixSocketClient(clientConfig); client.addFilter(new JsonClientFilter()); client.addFilter(new LoggingFilter()); }
Example #14
Source File: MySSLSocketFactory.java From Libraries-for-Android-Developers with MIT License | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore * @return */ 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(); } }
Example #15
Source File: HttpTaskFactory.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public HttpClient produce(InputStream keystore, String keypass) { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(keystore, keypass.toCharArray()); SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = basicParams(); 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(); } }
Example #16
Source File: AbstractGoogleClientFactory.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 6 votes |
/** * Replicates {@link ApacheHttpTransport#newDefaultHttpClient()} with one exception: * * 1 retry is allowed. * * @see DefaultHttpRequestRetryHandler */ DefaultHttpClient newDefaultHttpClient( SSLSocketFactory socketFactory, HttpParams params, ProxySelector proxySelector) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", socketFactory, 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, params); // retry only once defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true)); if (proxySelector != null) { defaultHttpClient.setRoutePlanner(new ProxySelectorRoutePlanner(registry, proxySelector)); } defaultHttpClient.setKeepAliveStrategy((response, context) -> KEEP_ALIVE_DURATION); return defaultHttpClient; }
Example #17
Source File: MySSLSocketFactory.java From android-project-wo2b with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #18
Source File: NetUtils.java From Conquer with Apache License 2.0 | 6 votes |
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(); } }
Example #19
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * 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(); } }
Example #20
Source File: MetricsClientFactory.java From galaxy-sdk-java with Apache License 2.0 | 6 votes |
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
Example #21
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * 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(); } }
Example #22
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * 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(); } }
Example #23
Source File: ClientFactory.java From galaxy-sdk-java with Apache License 2.0 | 6 votes |
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
Example #24
Source File: HTTPClientManager.java From ForgePE with GNU Affero General Public License v3.0 | 6 votes |
private HTTPClientManager() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); ConnManagerParams.setTimeout(params, 30000); params.setBooleanParameter("http.protocol.expect-continue", false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory; try { registry.register(new Scheme("https", NoCertSSLSocketFactory.createDefault(), 443)); } catch (Exception e) { Log.e("MCPE_ssl", "Couldn\\'t create SSLSocketFactory"); } ClientConnectionManager manager = new ThreadSafeClientConnManager(params, registry); this.mHTTPClient = new DefaultHttpClient(manager, params); }
Example #25
Source File: WeixinUtil.java From android-common-utils with Apache License 2.0 | 6 votes |
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(); } }
Example #26
Source File: EMQClientFactory.java From galaxy-sdk-java with Apache License 2.0 | 6 votes |
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory. ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
Example #27
Source File: TestSSLWrong.java From hk with GNU General Public License v3.0 | 6 votes |
public HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(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(); } }
Example #28
Source File: HttpAndroidClientFactory.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public HttpClient createHttpClient(ClientConfiguration clientconfiguration) { BasicHttpParams basichttpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(basichttpparams, clientconfiguration.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(basichttpparams, clientconfiguration.getSocketTimeout()); HttpConnectionParams.setStaleCheckingEnabled(basichttpparams, true); HttpConnectionParams.setTcpNoDelay(basichttpparams, true); int i = clientconfiguration.getSocketBufferSizeHints()[0]; int j = clientconfiguration.getSocketBufferSizeHints()[1]; if (i > 0 || j > 0) { HttpConnectionParams.setSocketBufferSize(basichttpparams, Math.max(i, j)); } SchemeRegistry schemeregistry = new SchemeRegistry(); schemeregistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (clientconfiguration.getProtocol() == Protocol.HTTPS) { schemeregistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } return new DefaultHttpClient(new SingleClientConnManager(basichttpparams, schemeregistry), basichttpparams); }
Example #29
Source File: AntennapodHttpClient.java From AntennaPodSP with MIT License | 5 votes |
private static SchemeRegistry prepareSchemeRegistry() { SchemeRegistry sr = new SchemeRegistry(); Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); sr.register(http); Scheme https = new Scheme("https", SSLSocketFactory.getSocketFactory(), 443); sr.register(https); return sr; }
Example #30
Source File: IgnorantHttpClient.java From hello-pinnedcerts with MIT License | 5 votes |
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme(HttpClientBuilder.HTTP_SCHEME, PlainSocketFactory.getSocketFactory(), HttpClientBuilder.HTTP_PORT)); registry.register(new Scheme(HttpClientBuilder.HTTPS_SCHEME, newSslSocketFactory(), HttpClientBuilder.HTTPS_PORT)); return new ThreadSafeClientConnManager(getParams(), registry); }