aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-17 14:00:25 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-17 14:00:25 +0200
commit6535dcb0044be778995a4f21b4bfbcfd81e1f888 (patch)
tree2c0e03ae914e308709f60a9696e4a6eba0c22377 /main/src/cgeo/geocaching/network
parent7e64bf85d832430172f88b3a1bbd691d6935f097 (diff)
downloadcgeo-6535dcb0044be778995a4f21b4bfbcfd81e1f888.zip
cgeo-6535dcb0044be778995a4f21b4bfbcfd81e1f888.tar.gz
cgeo-6535dcb0044be778995a4f21b4bfbcfd81e1f888.tar.bz2
Refactoring: use common method to retrieve JSON
Diffstat (limited to 'main/src/cgeo/geocaching/network')
-rw-r--r--main/src/cgeo/geocaching/network/Network.java22
1 files changed, 7 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java
index 7427fd4..e9e512f 100644
--- a/main/src/cgeo/geocaching/network/Network.java
+++ b/main/src/cgeo/geocaching/network/Network.java
@@ -266,15 +266,12 @@ public abstract class Network {
request.setHeader("Accept-Charset", "utf-8,iso-8859-1;q=0.8,utf-16;q=0.8,*;q=0.7");
request.setHeader("Accept-Language", "en-US,*;q=0.9");
request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
- return Network.doRequest(request);
- }
- private static HttpResponse doRequest(final HttpRequestBase request) {
- final String reqLogStr = request.getMethod() + " " + hidePassword(request.getURI().toString());
+ final String reqLogStr = request.getMethod() + " " + Network.hidePassword(request.getURI().toString());
Log.d(reqLogStr);
- final HttpClient client = getHttpClient();
- for (int i = 0; i <= NB_DOWNLOAD_RETRIES; i++) {
+ final HttpClient client = Network.getHttpClient();
+ for (int i = 0; i <= Network.NB_DOWNLOAD_RETRIES; i++) {
final long before = System.currentTimeMillis();
try {
final HttpResponse response = client.execute(request);
@@ -287,8 +284,8 @@ public abstract class Network {
return response;
} catch (IOException e) {
final String timeSpan = Network.formatTimeSpan(before);
- final String tries = (i + 1) + "/" + (NB_DOWNLOAD_RETRIES + 1);
- if (i == NB_DOWNLOAD_RETRIES) {
+ final String tries = (i + 1) + "/" + (Network.NB_DOWNLOAD_RETRIES + 1);
+ if (i == Network.NB_DOWNLOAD_RETRIES) {
Log.e("Failure " + tries + timeSpan + reqLogStr, e);
} else {
Log.e("Failure " + tries + " (" + e.toString() + ")" + timeSpan + "- retrying " + reqLogStr);
@@ -309,16 +306,11 @@ public abstract class Network {
}
public static JSONObject requestJSON(final String uri, final Parameters params) {
- final HttpGet request = new HttpGet(Network.prepareParameters(uri, params));
- request.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
- request.setHeader("Content-Type", "application/json; charset=UTF-8");
- request.setHeader("X-Requested-With", "XMLHttpRequest");
-
- final HttpResponse response = doRequest(request);
+ final HttpResponse response = getRequest(uri, params, new Parameters("Accept", "application/json, text/javascript, */*; q=0.01"));
if (response != null && response.getStatusLine().getStatusCode() == 200) {
try {
return new JSONObject(Network.getResponseData(response));
- } catch (JSONException e) {
+ } catch (final JSONException e) {
Log.e("Network.requestJSON", e);
}
}