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:com.su.search.client.solrj.PaHttpSolrServer.java
private DefaultHttpClient createClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ccm = new ThreadSafeClientConnManager(schemeRegistry); // Increase default max connection per route to 32 ccm.setDefaultMaxPerRoute(32);// ww w. j a v a 2 s. c om // Increase max total connection to 128 ccm.setMaxTotal(128); DefaultHttpClient httpClient = new DefaultHttpClient(ccm); httpClient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects); return httpClient; }
From source file:com.hp.saas.agm.rest.client.AliRestClient.java
private AliRestClient(String location, String domain, String project, String userName, String password, SessionStrategy sessionStrategy) { if (location == null) { throw new IllegalArgumentException("location==null"); }/*from ww w. j a va 2s . c o m*/ validateProjectAndDomain(domain, project); this.location = location; this.userName = userName; this.password = password; this.domain = domain; this.project = project; this.sessionStrategy = sessionStrategy; //HttpParams params = new BasicHttpParams(); //HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //HttpProtocolParams.setUseExpectContinue(params, true); //HttpProtocolParams.setUserAgent(params,"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) " // + "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1"); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); //httpCLient = new DefaultHttpClient(); //httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schReg), new BasicHttpParams()); //httpClient = new DefaultHttpClient(params); //httpClient = new DefaultHttpClient(); //setTimeout(DEFAULT_CLIENT_TIMEOUT); final int MAX_TOTAL_CONNECTIONS = 20; final int MAX_CONNECTIONS_PER_ROUTE = 20; final int TIMEOUT_CONNECT = 15000; final int TIMEOUT_READ = 15000; SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams connManagerParams = new BasicHttpParams(); HttpProtocolParams.setVersion(connManagerParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(connManagerParams, true); /*HttpProtocolParams.setUserAgent(connManagerParams,"Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) " + "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");*/ ConnPerRoute cpr = new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute httpRoute) { return 50; } }; ConnManagerParams.setMaxConnectionsPerRoute(connManagerParams, cpr); ConnManagerParams.setMaxTotalConnections(connManagerParams, MAX_TOTAL_CONNECTIONS); //ConnManagerParams.setMaxConnectionsPerRoute(connManagerParams, new ConnPerRouteBean(MAX_CONNECTIONS_PER_ROUTE)); HttpConnectionParams.setConnectionTimeout(connManagerParams, TIMEOUT_CONNECT); HttpConnectionParams.setSoTimeout(connManagerParams, TIMEOUT_READ); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(connManagerParams, schemeRegistry); httpClient = new DefaultHttpClient(cm, connManagerParams); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); responseFilters = new LinkedList<ResponseFilter>(); responseFilters.add(new IssueTicketFilter()); }
From source file:de.unwesen.packrat.api.APIBase.java
/*************************************************************************** * Implementation/*from www . j ava2 s . c o m*/ **/ public APIBase(Context context) { mContext = context; if (null == sConnectionManager || null == sClient) { // Set up an HttpClient instance that can be used by multiple threads HttpParams params = defaultHttpParams(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); sConnectionManager = new ThreadSafeClientConnManager(params, registry); sClient = new DefaultHttpClient(sConnectionManager, params); } }
From source file:com.cloudant.mazha.HttpRequests.java
private ClientConnectionManager getClientConnectionManager(HttpParams params) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); return new ThreadSafeClientConnManager(params, schemeRegistry); }
From source file:com.yunmall.ymsdk.net.http.AsyncHttpClient.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 w w w. j a v a 2s. c o m private static SchemeRegistry getDefaultSchemeRegistry(boolean fixNoHttpResponseException, int httpPort, int httpsPort) { if (fixNoHttpResponseException) { YmLog.d(LOG_TAG, "Beware! Using the fix is insecure, as it doesn't verify SSL certificates."); } if (httpPort < 1) { httpPort = 80; YmLog.d(LOG_TAG, "Invalid HTTP port number specified, defaulting to 80"); } if (httpsPort < 1) { httpsPort = 443; YmLog.d(LOG_TAG, "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(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort)); schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort)); return schemeRegistry; }
From source file:org.wso2.carbon.dynamic.client.web.app.registration.util.RemoteDCRClient.java
private static DefaultHttpClient getHTTPSClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme( DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }
From source file:org.mobicents.client.slee.resource.http.HttpClientResourceAdaptor.java
public void raActive() { activities = new ConcurrentHashMap<HttpClientActivityHandle, HttpClientActivity>(); executorService = Executors.newCachedThreadPool(); if (httpClientFactory != null) { httpclient = httpClientFactory.newHttpClient(); } else {//from www. java 2 s. co m HttpParams params = new SyncBasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager( schemeRegistry); threadSafeClientConnManager.setMaxTotal(maxTotal); for (Entry<HttpRoute, Integer> entry : maxForRoutes.entrySet()) { if (tracer.isInfoEnabled()) { tracer.info( String.format("Configuring MaxForRoute %s max %d", entry.getKey(), entry.getValue())); } threadSafeClientConnManager.setMaxForRoute(entry.getKey(), entry.getValue()); } httpclient = new DefaultHttpClient(threadSafeClientConnManager, params); } isActive = true; if (tracer.isInfoEnabled()) { tracer.info(String.format("HttpClientResourceAdaptor=%s entity activated.", this.resourceAdaptorContext.getEntityName())); } }
From source file:com.alphabetbloc.accessmrs.utilities.NetworkUtils.java
public static HttpClient createHttpClient(SocketFactory socketFactory) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, false); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); // HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT); // Times out Active Connection HttpClientParams.setRedirecting(params, false); ConnManagerParams.setTimeout(params, CONNECTION_TIMEOUT); ConnPerRoute connPerRoute = new ConnPerRouteBean(MAX_CONN_PER_ROUTE); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); ConnManagerParams.setMaxTotalConnections(params, MAX_CONNECTIONS); SchemeRegistry schemeRegistry = new SchemeRegistry(); SocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); if (socketFactory != null) { sslSocketFactory = socketFactory; }/*from w ww.ja va 2 s. co m*/ try { schemeRegistry.register(new Scheme("http", sslSocketFactory, 80)); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); schemeRegistry.register(new Scheme("https", sslSocketFactory, 8443)); } catch (Exception e) { Log.e(TAG, "Caught an EXCEPTION. could not register the scheme?"); e.printStackTrace(); } ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient httpClient = new DefaultHttpClient(cm, params); return httpClient; }
From source file:luki.x.net.XNetEngine.java
/** * getHttpClient//w w w .ja v a 2 s . c om * * @return */ private HttpClient getHttpClient() { // ? // httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("", 0)); // httpParams.removeParameter(ConnRoutePNames.DEFAULT_PROXY); if (httpClient == null) { // timeout: get connections from connection pool ConnManagerParams.setTimeout(httpParams, 1000); // timeout: connect to the server HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT); // timeout: transfer data from server HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT); // set max connections per host ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_HOST_CONNECTIONS)); // set max total connections ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); // use expect-continue handshake HttpProtocolParams.setUseExpectContinue(httpParams, true); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, charSet); // disable Nagle algorithm HttpConnectionParams.setTcpNoDelay(httpParams, true); // scheme: http and https SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager manager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpClient = new DefaultHttpClient(manager, httpParams); } return httpClient; }
From source file:fr.itinerennes.ItineRennesApplication.java
/** * Gets a reference to the HttpClient./*from www . j a v a 2 s . c o m*/ * * @return a reference to the {@link ProgressHttpClient} */ public final HttpClient getHttpClient() { if (httpClient == null) { final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); final HttpParams cxParams = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(cxParams, 5); HttpConnectionParams.setConnectionTimeout(cxParams, 60000); final ThreadSafeClientConnManager connexionManager = new ThreadSafeClientConnManager(cxParams, registry); final String appVersion = VersionUtils.getCurrent(this); final String userAgent = String.format("ItineRennes/%s (Android/%s; SDK %s; %s; %s)", appVersion, android.os.Build.VERSION.RELEASE, android.os.Build.VERSION.SDK_INT, android.os.Build.MODEL, android.os.Build.DEVICE); final HttpParams clientParams = new BasicHttpParams(); clientParams.setParameter(HttpProtocolParams.USER_AGENT, userAgent); httpClient = new DefaultHttpClient(connexionManager, clientParams); } return httpClient; }