From dd95973d2df3d5be85306e0c0eb34d56df882ade Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Mon, 30 Apr 2012 13:24:25 +0200 Subject: [PATCH] Use AndroidHttpClient. --- src/org/fox/ttrss/ApiRequest.java | 22 ++++++++++------------ src/org/fox/ttrss/FeedsFragment.java | 21 +++++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/org/fox/ttrss/ApiRequest.java b/src/org/fox/ttrss/ApiRequest.java index bea5ce5a..c514387c 100644 --- a/src/org/fox/ttrss/ApiRequest.java +++ b/src/org/fox/ttrss/ApiRequest.java @@ -111,18 +111,10 @@ public class ApiRequest extends AsyncTask, Integer, JsonE if (m_transportDebugging) Log.d(TAG, ">>> (" + requestStr + ") " + m_api); - DefaultHttpClient client; + AndroidHttpClient client = AndroidHttpClient.newInstance("Tiny Tiny RSS"); if (m_trustAny) { - SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); - - HttpParams httpParams = new BasicHttpParams(); - - client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams); - } else { - client = new DefaultHttpClient(); + client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", new EasySSLSocketFactory(), 443)); } try { @@ -141,6 +133,8 @@ public class ApiRequest extends AsyncTask, Integer, JsonE return null; } + HttpContext context = null; + String httpLogin = m_prefs.getString("http_login", "").trim(); String httpPassword = m_prefs.getString("http_password", "").trim(); @@ -157,14 +151,18 @@ public class ApiRequest extends AsyncTask, Integer, JsonE } HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); + CredentialsProvider cp = new BasicCredentialsProvider(); + context = new BasicHttpContext(); - client.getCredentialsProvider().setCredentials( + cp.setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(httpLogin, httpPassword)); + + context.setAttribute(ClientContext.CREDS_PROVIDER, cp); } httpPost.setEntity(new StringEntity(requestStr, "utf-8")); - HttpResponse execute = client.execute(httpPost); + HttpResponse execute = client.execute(httpPost, context); m_httpStatusCode = execute.getStatusLine().getStatusCode(); diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 836a5b0c..459ba077 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -487,21 +487,14 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } protected void downloadFile(String fetchUrl, String outputFile) { - DefaultHttpClient client; + AndroidHttpClient client = AndroidHttpClient.newInstance("Tiny Tiny RSS"); if (m_prefs.getBoolean("ssl_trust_any", false)) { - SchemeRegistry schemeRegistry = new SchemeRegistry(); - schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); - - HttpParams httpParams = new BasicHttpParams(); - - client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams); - } else { - client = new DefaultHttpClient(); + client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", new EasySSLSocketFactory(), 443)); } HttpGet httpGet = new HttpGet(fetchUrl); + HttpContext context = null; String httpLogin = m_prefs.getString("http_login", ""); String httpPassword = m_prefs.getString("http_password", ""); @@ -517,15 +510,19 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } HttpHost targetHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); + CredentialsProvider cp = new BasicCredentialsProvider(); + context = new BasicHttpContext(); - client.getCredentialsProvider().setCredentials( + cp.setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(httpLogin, httpPassword)); + + context.setAttribute(ClientContext.CREDS_PROVIDER, cp); } try { - HttpResponse execute = client.execute(httpGet); + HttpResponse execute = client.execute(httpGet, context); InputStream content = execute.getEntity().getContent();