Skip to content

Commit

Permalink
fixed: ARTE: Request scheitern mit 429
Browse files Browse the repository at this point in the history
closed #301
  • Loading branch information
alex1702 committed Dec 4, 2017
2 parents dd27ca0 + 07cb771 commit 7eefeb6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply from: "${project.rootDir}/gradle/eclipse.gradle"
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'de.mediathekview'
version = '3.1.38'
version = '3.1.39'

def jarName = 'MServer.jar'
def mainClass = 'mServer.Main'
Expand Down
32 changes: 25 additions & 7 deletions src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.mediathekview.mlib.tool.MVHttpClient;
import java.io.IOException;
import java.util.logging.Level;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -27,14 +28,31 @@ public static <T extends Object> T executeRequest(Logger logger, Gson gson, Stri
OkHttpClient httpClient = mvhttpClient.getHttpClient();
Request request = new Request.Builder()
.addHeader(AUTH_HEADER, AUTH_TOKEN)
.addHeader("User-Agent", "Fiddler")
.url(aUrl).build();
try (Response response = httpClient.newCall(request).execute()) {
if(response.isSuccessful()) {
result = gson.fromJson(response.body().string(), aDtoType);
} else {
logger.error(String.format("ARTE Request '%s' failed: %s", aUrl, response.code()));
}
}

boolean stop = false;

do {
Call call = httpClient.newCall(request);
try (Response response = call.execute()) {
if(response.isSuccessful()) {
result = gson.fromJson(response.body().string(), aDtoType);
stop = true;
} else {
if(response.code() != 429) {
logger.error(String.format("ARTE Request '%s' failed: %s", aUrl, response.code()));
stop = true;
} else {
// bei 429 (too many requests) warten und nochmal versuchen
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
}
}
}
}
} while(!stop);

} catch (IOException ex) {
logger.error("Beim laden der Filme für Arte kam es zu Verbindungsproblemen.", ex);
Expand Down

0 comments on commit 7eefeb6

Please sign in to comment.