List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager
@Deprecated public ThreadSafeClientConnManager(final HttpParams params, final SchemeRegistry schreg)
From source file:com.android.dumprendertree2.FsUtils.java
private static HttpClient getHttpClient() { if (sHttpClient == null) { HttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(/*w w w . ja v a 2s . c om*/ new Scheme("http", PlainSocketFactory.getSocketFactory(), ForwarderManager.HTTP_PORT)); schemeRegistry.register( new Scheme("https", SSLSocketFactory.getSocketFactory(), ForwarderManager.HTTPS_PORT)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); sHttpClient = new DefaultHttpClient(connectionManager, params); HttpConnectionParams.setSoTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS); HttpConnectionParams.setConnectionTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS); } return sHttpClient; }
From source file:com.google.appinventor.components.runtime.util.WebServiceUtil.java
/** * Returns the one <code>WebServiceUtil</code> instance * @return the one <code>WebServiceUtil</code> instance *///from w w w.ja v a 2s . co m 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; }
From source file:com.squeezecontrol.image.HttpFetchingImageStore.java
public HttpFetchingImageStore(String baseUrl, String username, String password) { this.baseUrl = baseUrl; 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 20 seconds. Tweak to taste. HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager mgr = new ThreadSafeClientConnManager(params, schemeRegistry); mClient = new DefaultHttpClient(mgr, params); if (username != null && !"".equals(username)) { Credentials defaultcreds = new UsernamePasswordCredentials("dag", "test"); mClient.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); }//from ww w. j av a 2s .co m }
From source file:com.akop.bach.util.IgnorantHttpClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.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); return new ThreadSafeClientConnManager(params, registry); }
From source file:org.changhong.sync.web.MySSLSocketFactory.java
public static DefaultHttpClient getNewHttpClient() { try {// w w w .j a v a 2s . co m 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(); } }
From source file:com.inferiorhumanorgans.WayToGo.Agency.BART.Route.RouteTask.java
@Override protected Void doInBackground(BARTAgency... someAgencies) { super.doInBackground(someAgencies); Log.i(LOG_NAME, "Trying to get BART route list."); InputStream content = null;/*from w ww . ja va2s .c o m*/ ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient hc = new DefaultHttpClient(connman, params); Log.i(LOG_NAME, "Fetching from: " + BART_URL + BARTAgency.API_KEY); HttpGet getRequest = new HttpGet(BART_URL + BARTAgency.API_KEY); try { content = hc.execute(getRequest).getEntity().getContent(); } catch (ClientProtocolException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } Log.i(LOG_NAME, "Put the station list in the background."); try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(dataHandler); xr.parse(new InputSource(content)); } catch (ParserConfigurationException pce) { Log.e(LOG_NAME + " SAX XML", "sax parse error", pce); } catch (AbortXMLParsingException abrt) { Log.i(LOG_NAME + " AsyncXML", "Cancelled!!!!!"); } catch (SAXException se) { Log.e(LOG_NAME + " SAX XML", "sax error", se); } catch (IOException ioe) { Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe); } Log.i(LOG_NAME + " SAX XML", "Done parsing BART station XML"); return null; }
From source file:chen.android.toolkit.network.HttpConnection.java
/** * </br><b>title : </b> HttpClient * </br><b>description :</b>TODO * </br><b>time :</b> 2012-7-10 ?10:49:35 * @param charset//from w ww .j a v a2 s. c om * @return */ public static HttpClient createHttpClient(String charset) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, charset); HttpProtocolParams.setUseExpectContinue(params, true); HttpProtocolParams.setUserAgent(params, USER_AGENT); ConnManagerParams.setTimeout(params, 1 * 1000); HttpConnectionParams.setConnectionTimeout(params, 2 * 1000); HttpConnectionParams.setSoTimeout(params, 4 * 1000); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); // ??HttpClient ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); }
From source file:com.alibaba.akita.io.HttpInvoker.java
/** * init/*from w ww . j a va 2 s . co m*/ */ private static void init() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", _FakeSSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); HttpConnectionParams.setConnectionTimeout(params, 8000); HttpConnectionParams.setSoTimeout(params, 15000); params.setBooleanParameter("http.protocol.expect-continue", false); connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); client = new DefaultHttpClient(connectionManager, params); // enable gzip support in Request and Response. client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); //Log.i("ContentLength", entity.getContentLength()+""); 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; } } } } }); }
From source file:br.gov.frameworkdemoiselle.behave.integration.alm.httpsclient.HttpsClient.java
public static HttpClient getNewHttpClient(String encoding) { try {// w ww .ja va2 s .c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, encoding); 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(); } }
From source file:pt.hive.cameo.net.ClientFactory.java
public static DefaultHttpClient getHttpClient(boolean strict) { // creates a new instance of the basic http parameters and then // updates the parameter with a series of pre-defined options that // are defined as the default ones for this factory HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.strict-transfer-encoding", false); params.setBooleanParameter("http.protocol.expect-continue", true); // constructs both the plain and the secure factory objects that are // going to be used in the registration of the plain and secure http // schemes, operation to be performed latter on SocketFactory plainFactory = PlainSocketFactory.getSocketFactory(); SocketFactory secureFactory = strict ? org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory() : SSLSocketFactory.getSocketFactory(); // creates the registry object and registers both the secure and the // insecure http mechanisms for the respective socket factories SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", plainFactory, 80)); registry.register(new Scheme("https", secureFactory, 443)); // creates the manager entity using the creates parameters structure // and the registry for socket factories ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); // creates the default http client using the created thread safe manager // with the provided parameters and registry (as expected) and then // returns the new client to the caller method so that it may be used DefaultHttpClient client = new DefaultHttpClient(manager, params); return client; }