List of usage examples for org.apache.http.conn.ssl SSLSocketFactory getSocketFactory
public static SSLSocketFactory getSocketFactory() throws SSLInitializationException
cacerts
file in the security properties directory). From source file:edu.mit.mobile.android.locast.net.NetworkClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); return new ThreadSafeClientConnManager(getParams(), registry); }
From source file:com.da.daum.DaumCafeBungImgList.java
private HttpClient getPoolHttpClient() { HttpClient httpclient;// w ww .java 2 s . co m SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection to 200 cm.setMaxTotal(200); // Increase default max connection per route to 20 cm.setDefaultMaxPerRoute(20); // Increase max connections for localhost:80 to 50 HttpHost localhost = new HttpHost("locahost", 80); cm.setMaxPerRoute(new HttpRoute(localhost), 50); //DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient = new DefaultHttpClient(cm); return httpclient; }
From source file:org.apache.marmotta.platform.core.services.http.HttpClientServiceImpl.java
@PostConstruct protected void initialize() { try {/*from ww w .j a va 2 s .c o m*/ lock.writeLock().lock(); httpParams = new BasicHttpParams(); String userAgentString = "Apache Marmotta/" + configurationService.getStringConfiguration("kiwi.version") + " (running at " + configurationService.getServerUri() + ")" + " lmf-core/" + configurationService.getStringConfiguration("kiwi.version"); userAgentString = configurationService.getStringConfiguration("core.http.user_agent", userAgentString); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, configurationService.getIntConfiguration("core.http.so_timeout", 60000)); httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, configurationService.getIntConfiguration("core.http.connection_timeout", 10000)); httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS, 20)); cm.setDefaultMaxPerRoute( configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS_PER_ROUTE, 10)); final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams); hc.setRedirectStrategy(new LMFRedirectStrategy()); hc.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler()); hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class); hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString)); if (configurationService.getBooleanConfiguration(CoreOptions.HTTP_CLIENT_CACHE_ENABLE, true)) { CacheConfig cacheConfig = new CacheConfig(); // FIXME: Hardcoded constants - is this useful? cacheConfig.setMaxCacheEntries(1000); cacheConfig.setMaxObjectSize(81920); final HttpCacheStorage cacheStore = new MapHttpCacheStorage(httpCache); this.httpClient = new MonitoredHttpClient(new CachingHttpClient(hc, cacheStore, cacheConfig)); } else { this.httpClient = new MonitoredHttpClient(hc); } bytesSent.set(0); bytesReceived.set(0); requestsExecuted.set(0); idleConnectionMonitorThread = new IdleConnectionMonitorThread(httpClient.getConnectionManager()); idleConnectionMonitorThread.start(); StatisticsProvider stats = new StatisticsProvider(cm); statisticsService.registerModule(HttpClientService.class.getSimpleName(), stats); } finally { lock.writeLock().unlock(); } }
From source file:org.hupo.psi.mi.psicquic.ws.legacy.SolrBasedPsicquicRestService10.java
private HttpClient createHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(SolrBasedPsicquicService.maxTotalConnections); cm.setDefaultMaxPerRoute(SolrBasedPsicquicService.defaultMaxConnectionsPerHost); HttpClient httpClient = new DefaultHttpClient(cm); String proxyHost = config.getProxyHost(); String proxyPort = config.getProxyPort(); if (isValueSet(proxyHost) && proxyHost.trim().length() > 0 && isValueSet(proxyPort) && proxyPort.trim().length() > 0) { try {//from ww w .j a v a 2 s. c om HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort)); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } catch (Exception e) { logger.error("Impossible to create proxy host:" + proxyHost + ", port:" + proxyPort, e); } } return httpClient; }
From source file:org.onebusaway.siri.core.SiriCommon.java
/**** * Setup Methods//ww w . ja va2 s .com ****/ @PostConstruct public void start() { HttpParams params = new BasicHttpParams(); /** * Override the default local address used for outgoing http client * connections, if specified */ if (_localAddress != null) { params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, _localAddress); } /** * Set the timeout for both connections to a socket and for reading from a * socket. */ if (_connectionTimeout != 0) { HttpConnectionParams.setConnectionTimeout(params, _connectionTimeout * 1000); HttpConnectionParams.setSoTimeout(params, _connectionTimeout * 1000); } /** * We want to allow a fair-amount of concurrent connections. TODO: Can we * auto-tune this somehow? */ ConnManagerParams.setMaxTotalConnections(params, 50); /** * We want to create a connection manager that can pool multiple * connections. */ SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); _client = new DefaultHttpClient(connectionManager, params); }
From source file:me.xiaopan.android.gohttp.HttpClientManager.java
/** * Returns default instance of SchemeRegistry * * @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification * @param httpPort HTTP port to be used, must be greater than 0 * @param httpsPort HTTPS port to be used, must be greater than 0 *///from ww w . j a v a2 s.c o m private static SchemeRegistry getDefaultSchemeRegistry(boolean fixNoHttpResponseException, int httpPort, int httpsPort) { if (fixNoHttpResponseException) { Log.d(GoHttp.class.getSimpleName(), "Beware! Using the fix is insecure, as it doesn't verify SSL certificates."); } if (httpPort < 1) { httpPort = 80; Log.d(GoHttp.class.getSimpleName(), "Invalid HTTP port number specified, defaulting to 80"); } if (httpsPort < 1) { httpsPort = 443; Log.d(GoHttp.class.getSimpleName(), "Invalid HTTPS port number specified, defaulting to 443"); } // Fix to SSL flaw in API < ICS // See https://code.google.com/p/android/issues/detail?id=13117 SSLSocketFactory sslSocketFactory; if (fixNoHttpResponseException) { sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory(); } else { sslSocketFactory = SSLSocketFactory.getSocketFactory(); } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort)); schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort)); return schemeRegistry; }
From source file:com.bt.download.android.core.HttpFetcher.java
private static HttpClient setupHttpClient(boolean gzip) { SSLSocketFactory.getSocketFactory().setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicHttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(20)); params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 200); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient httpClient = new DefaultHttpClient(cm, new BasicHttpParams()); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_RETRY_COUNT, true)); if (gzip) {//from w w w . j a va 2 s. c o m httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); } return httpClient; }
From source file:com.pmi.restlet.ext.httpclient.HttpClientHelper.java
/** * Configures the scheme registry. By default, it registers the HTTP and the * HTTPS schemes./* w w w . ja v a2 s . c om*/ * * @param schemeRegistry * The scheme registry to configure. */ protected void configure(SchemeRegistry schemeRegistry) { schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = null; SslContextFactory sslContextFactory = SslUtils.getSslContextFactory(this); if (sslContextFactory != null) { try { SSLContext sslContext = sslContextFactory.createSslContext(); sslSocketFactory = new SSLSocketFactory(sslContext); } catch (Exception e) { throw new RuntimeException("Unable to create SSLContext.", e); } } else { sslSocketFactory = SSLSocketFactory.getSocketFactory(); } schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); }
From source file:com.udps.hive.jdbc.HiveConnection.java
private DefaultHttpClient getHttpClient(Boolean useSsl) throws SQLException { DefaultHttpClient httpClient = new DefaultHttpClient(); // Request interceptor for any request pre-processing logic HttpRequestInterceptor requestInterceptor; // If Kerberos if (isKerberosAuthMode()) { if (useSsl) { String msg = "SSL encryption is currently not supported with " + "kerberos authentication"; throw new SQLException(msg, " 08S01"); }/*from ww w . ja va 2 s . c o m*/ /** * Add an interceptor which sets the appropriate header in the * request. It does the kerberos authentication and get the final * service ticket, for sending to the server before every request. */ requestInterceptor = new HttpKerberosRequestInterceptor(sessConfMap.get(HIVE_AUTH_PRINCIPAL), host, getServerHttpUrl(false)); } else { /** * Add an interceptor to pass username/password in the header. In * https mode, the entire information is encrypted */ requestInterceptor = new HttpBasicAuthInterceptor(getUserName(), getPassword()); // Configure httpClient for SSL if (useSsl) { String sslTrustStorePath = sessConfMap.get(HIVE_SSL_TRUST_STORE); String sslTrustStorePassword = sessConfMap.get(HIVE_SSL_TRUST_STORE_PASSWORD); KeyStore sslTrustStore; SSLSocketFactory socketFactory; try { if (sslTrustStorePath == null || sslTrustStorePath.isEmpty()) { // Create a default socket factory based on standard // JSSE trust material socketFactory = SSLSocketFactory.getSocketFactory(); } else { // Pick trust store config from the given path sslTrustStore = KeyStore.getInstance(HIVE_SSL_TRUST_STORE_TYPE); sslTrustStore.load(new FileInputStream(sslTrustStorePath), sslTrustStorePassword.toCharArray()); socketFactory = new SSLSocketFactory(sslTrustStore); } socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sslScheme = new Scheme("https", 443, socketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(sslScheme); } catch (Exception e) { String msg = "Could not create an https connection to " + jdbcURI + ". " + e.getMessage(); throw new SQLException(msg, " 08S01", e); } } } httpClient.addRequestInterceptor(requestInterceptor); return httpClient; }