Browse Source

Fixed Nullpointer Exception on saveGeneralData

Increased RetryTimes
Decreased Activities per_page value while getting the activities
master
Bianca Steffes 3 years ago
parent
commit
fc2bd1126c
  1. 23
      export/src/export/Main.java

23
export/src/export/Main.java

@ -36,9 +36,9 @@ public class Main
{ {
public static final String baseUrl = "https://www.strava.com/api/v3/"; public static final String baseUrl = "https://www.strava.com/api/v3/";
public static final String tokenUrl = "https://www.strava.com/api/v3/oauth/token"; public static final String tokenUrl = "https://www.strava.com/api/v3/oauth/token";
private static final int retryTimes = 20;
private static final int retryTimes = 100;
private static final int httpCodeLimitReached = 429; private static final int httpCodeLimitReached = 429;
private static int athleteId = 0;
private static int athleteId = -1;
private static JSONParser parser = new JSONParser(); private static JSONParser parser = new JSONParser();
private static String testRequest; private static String testRequest;
private static File errorFile; private static File errorFile;
@ -191,7 +191,8 @@ public class Main
int pageIndex = 1; int pageIndex = 1;
while (true) while (true)
{ {
String requestExtension = "athlete/activities?per_page=500&page=" + pageIndex;
//TODO: this 'per_page' value could perhaps be the root of all evil
String requestExtension = "athlete/activities?per_page=100&page=" + pageIndex;
String json = makeGetRequestWithRetry(requestExtension, token); String json = makeGetRequestWithRetry(requestExtension, token);
if (json==null || json.isEmpty() || json.isBlank() || json.equals("") || json.equals("[]")) // don't know where the last page is... if (json==null || json.isEmpty() || json.isBlank() || json.equals("") || json.equals("[]")) // don't know where the last page is...
{ {
@ -279,6 +280,7 @@ public class Main
//tried enough times, so stop now //tried enough times, so stop now
if(count >= retryTimes) if(count >= retryTimes)
{ {
writeError("Athlete: "+athleteId+" Retry limit reached. Last error code: "+e.getResponseCode());
return null; return null;
} }
//request limit is reached, try again later //request limit is reached, try again later
@ -341,6 +343,11 @@ public class Main
writeError("Athlete " + athleteId + ": Error parsing general information."); writeError("Athlete " + athleteId + ": Error parsing general information.");
return null; return null;
} }
catch (NullPointerException e)
{
writeError("Athlete " + athleteId + ": No general information found.");
return null;
}
} }
/** /**
@ -415,7 +422,7 @@ public class Main
} }
catch (IOException e) catch (IOException e)
{ {
writeError("Error while handling GET request: " + e.toString());
writeError("Athlete: "+athleteId+" Error while handling GET request: " + e.toString());
} }
return ""; return "";
} }
@ -437,7 +444,7 @@ public class Main
//excluded error messages appearing on missing streams and reached rate limit //excluded error messages appearing on missing streams and reached rate limit
if(responseCode != HttpURLConnection.HTTP_NOT_FOUND && responseCode!= httpCodeLimitReached) if(responseCode != HttpURLConnection.HTTP_NOT_FOUND && responseCode!= httpCodeLimitReached)
{ {
writeError("Wrong response code: " + responseCode);
writeError("Athlete: "+athleteId+" Wrong response code: " + responseCode);
} }
throw new ResponseCodeWrongException(responseCode); throw new ResponseCodeWrongException(responseCode);
} }
@ -503,7 +510,7 @@ public class Main
} }
catch (IOException e) catch (IOException e)
{ {
writeError("Error while handling POST request: " + e.toString());
writeError("Athlete: "+athleteId+"Error while handling POST request: " + e.toString());
} }
return ""; return "";
} }
@ -579,11 +586,12 @@ public class Main
int zipcount =1; int zipcount =1;
for (Triplet oneUser : refreshTokens) for (Triplet oneUser : refreshTokens)
{ {
athleteId++;
// a is access_token and b is new refresh_token // a is access_token and b is new refresh_token
Tuple withAccessToken = getAccessToken(oneUser); Tuple withAccessToken = getAccessToken(oneUser);
if (withAccessToken == null) if (withAccessToken == null)
{ {
writeError("Coulnd't get new access token for client "+athleteId);
writeError("Couldn't get new access token for client "+athleteId);
continue; continue;
} }
newRefreshTokens.add(new Triplet(oneUser.getA(), oneUser.getB(), withAccessToken.getB())); newRefreshTokens.add(new Triplet(oneUser.getA(), oneUser.getB(), withAccessToken.getB()));
@ -607,7 +615,6 @@ public class Main
writeError("Files coulnd't be zipped"); writeError("Files coulnd't be zipped");
} }
} }
athleteId++;
} }
//zip the rest //zip the rest
try try

Loading…
Cancel
Save