1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Merge branch 'Zillode-fix-npe-jsontokener'

This commit is contained in:
Felix Ableitner 2015-03-24 00:56:01 +01:00
commit 24ba984ec5

View file

@ -49,34 +49,42 @@ public class GetTask extends AsyncTask<String, Void, String> {
*/ */
@Override @Override
protected String doInBackground(String... params) { protected String doInBackground(String... params) {
String fullUri = params[0] + params[1]; // Retry at most 10 times before failing
HttpClient httpclient = new DefaultHttpClient(); for (int i = 0; i < 10; i++) {
if (params.length == 5) { String fullUri = params[0] + params[1];
LinkedList<NameValuePair> urlParams = new LinkedList<>(); HttpClient httpclient = new DefaultHttpClient();
urlParams.add(new BasicNameValuePair(params[3], params[4])); if (params.length == 5) {
fullUri += "?" + URLEncodedUtils.format(urlParams, HTTP.UTF_8); LinkedList<NameValuePair> urlParams = new LinkedList<>();
} urlParams.add(new BasicNameValuePair(params[3], params[4]));
HttpGet get = new HttpGet(fullUri); fullUri += "?" + URLEncodedUtils.format(urlParams, HTTP.UTF_8);
get.addHeader(new BasicHeader(RestApi.HEADER_API_KEY, params[2]));
try {
HttpResponse response = httpclient.execute(get);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
String result = "";
while ((line = br.readLine()) != null) {
result += line;
}
br.close();
return result;
} }
} catch (IOException e) { HttpGet get = new HttpGet(fullUri);
Log.w(TAG, "Failed to call Rest API at " + fullUri, e); get.addHeader(new BasicHeader(RestApi.HEADER_API_KEY, params[2]));
try {
HttpResponse response = httpclient.execute(get);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
String result = "";
while ((line = br.readLine()) != null) {
result += line;
}
br.close();
return result;
}
} catch (IOException e) {
Log.w(TAG, "Failed to call Rest API at " + fullUri, e);
}
try {
// Don't push the API too hard
Thread.sleep(100);
} catch (InterruptedException e) { }
Log.w(TAG, "Retrying GetTask Rest API call ("+i+")");
} }
return null; return null;
} }