org.apache.http.conn.scheme.SchemeRegistry Java Examples
The following examples show how to use
org.apache.http.conn.scheme.SchemeRegistry.
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: 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 #3
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 #4
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 #5
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 #6
Source File: RestClient.java From s2g-zuul with MIT License | 6 votes |
public KeyStore getKeyStore(){ SchemeRegistry registry = httpClient4.getConnectionManager().getSchemeRegistry(); if(! registry.getSchemeNames().contains("https")){ throw new IllegalStateException("Registry does not include an 'https' entry."); } SchemeSocketFactory awareSocketFactory = httpClient4.getConnectionManager().getSchemeRegistry().getScheme("https").getSchemeSocketFactory(); if(awareSocketFactory instanceof KeyStoreAwareSocketFactory){ return ((KeyStoreAwareSocketFactory) awareSocketFactory).getKeyStore(); }else{ throw new IllegalStateException("Cannot extract keystore from scheme socket factory of type: " + awareSocketFactory.getClass().getName()); } }
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: 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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: AsyncHttpClient.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public AsyncHttpClient(SchemeRegistry schemeregistry) { a = 10; b = 10000; h = true; BasicHttpParams basichttpparams = new BasicHttpParams(); ConnManagerParams.setTimeout(basichttpparams, b); ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a)); ConnManagerParams.setMaxTotalConnections(basichttpparams, 10); HttpConnectionParams.setSoTimeout(basichttpparams, b); HttpConnectionParams.setConnectionTimeout(basichttpparams, b); HttpConnectionParams.setTcpNoDelay(basichttpparams, true); HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192); HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1); ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry); e = getDefaultThreadPool(); f = new WeakHashMap(); g = new HashMap(); d = new SyncBasicHttpContext(new BasicHttpContext()); c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams); c.addRequestInterceptor(new a(this)); c.addResponseInterceptor(new b(this)); c.addRequestInterceptor(new c(this), 0); c.setHttpRequestRetryHandler(new z(5, 1500)); }
Example #19
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 #20
Source File: SocketFactoryHttpClientFactory.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public DefaultHttpClient create(final HttpMethod method, final URI uri) { final TrustStrategy acceptTrustStrategy = new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] certificate, final String authType) { return true; } }; final SchemeRegistry registry = new SchemeRegistry(); try { final SSLSocketFactory ssf = new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf)); } catch (Exception e) { throw new ODataRuntimeException(e); } final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry)); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT); return httpClient; }
Example #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
Source File: HttpsUtils.java From RipplePower with Apache License 2.0 | 5 votes |
public 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); HttpProtocolParams.setUserAgent(params, HttpHeader.getUA()); 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); DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params); httpClient.setCookieStore(new BasicCookieStore()); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 25000); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 25000); return httpClient; } catch (Exception e) { return new DefaultHttpClient(); } }
Example #29
Source File: HttpClientFactory.java From io with Apache License 2.0 | 5 votes |
/** * HTTPClientオブジェクトを作成. * @param type 通信タイプ * @param connectionTimeout タイムアウト値(ミリ秒)。0の場合はデフォルト値を利用する。 * @return 作成したHttpClientクラスインスタンス */ public static HttpClient create(final String type, final int connectionTimeout) { if (TYPE_DEFAULT.equalsIgnoreCase(type)) { return new DefaultHttpClient(); } SSLSocketFactory sf = null; try { if (TYPE_INSECURE.equalsIgnoreCase(type)) { sf = createInsecureSSLSocketFactory(); } } catch (Exception e) { return null; } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", PORTHTTPS, sf)); schemeRegistry.register(new Scheme("http", PORTHTTP, PlainSocketFactory.getSocketFactory())); HttpParams params = new BasicHttpParams(); ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry); // ClientConnectionManager cm = new // ThreadSafeClientConnManager(schemeRegistry); HttpClient hc = new DefaultHttpClient(cm, params); HttpParams params2 = hc.getParams(); int timeout = TIMEOUT; if (connectionTimeout != 0) { timeout = connectionTimeout; } HttpConnectionParams.setConnectionTimeout(params2, timeout); // 接続のタイムアウト HttpConnectionParams.setSoTimeout(params2, timeout); // データ取得のタイムアウト return hc; }
Example #30
Source File: EasyHttpClient.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * Function that creates a ClientConnectionManager which can handle http and https. * In case of https self signed or invalid certificates will be accepted. */ @Override protected ClientConnectionManager createClientConnectionManager() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT)); registry.register(new Scheme("https", new EasySSLSocketFactory(), HTTPS_PORT)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); return manager; }