From 3db7b366622d70d0c4831c4d716dca753685fb2d Mon Sep 17 00:00:00 2001 From: hgomez Date: Sun, 5 Nov 2017 18:36:44 -0500 Subject: [PATCH] Removed comments from author, reformat --- .../DailyMotionExample.java | 30 ++++++++----------- .../googlehttpclientguide/DailyMotionUrl.java | 19 ++++-------- .../baeldung/googlehttpclientguide/Video.java | 27 ++++++++--------- .../googlehttpclientguide/VideoFeed.java | 17 ++++------- 4 files changed, 36 insertions(+), 57 deletions(-) diff --git a/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionExample.java b/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionExample.java index dd559f3aa2..dc0fb1e1c5 100644 --- a/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionExample.java +++ b/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionExample.java @@ -1,25 +1,16 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.googlehttpclientguide; +import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestFactory; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpResponseException; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.JsonObjectParser; -import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.ExponentialBackOff; -/** - * - * @author Hugo - */ public class DailyMotionExample { static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); @@ -29,15 +20,20 @@ public class DailyMotionExample { private static void run() throws Exception { HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory( - new HttpRequestInitializer() { - - public void initialize(HttpRequest request) { - request.setParser(new JsonObjectParser(JSON_FACTORY)); - } - }); + (HttpRequest request) -> { + request.setParser(new JsonObjectParser(JSON_FACTORY)); + }); DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/"); url.fields = "id,tags,title,url"; HttpRequest request = requestFactory.buildGetRequest(url); + ExponentialBackOff backoff = new ExponentialBackOff.Builder() + .setInitialIntervalMillis(500) + .setMaxElapsedTimeMillis(900000) + .setMaxIntervalMillis(6000) + .setMultiplier(1.5) + .setRandomizationFactor(0.5) + .build(); + request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff)); VideoFeed videoFeed = request.execute().parseAs(VideoFeed.class); if (videoFeed.list.isEmpty()) { System.out.println("No videos found."); diff --git a/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionUrl.java b/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionUrl.java index 0f77cdd2f6..ebfc63d492 100644 --- a/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionUrl.java +++ b/libraries/src/main/java/com/baeldung/googlehttpclientguide/DailyMotionUrl.java @@ -1,22 +1,15 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.googlehttpclientguide; import com.google.api.client.http.GenericUrl; import com.google.api.client.util.Key; -/** - * - * @author Hugo - */ - public class DailyMotionUrl extends GenericUrl { + +public class DailyMotionUrl extends GenericUrl { public DailyMotionUrl(String encodedUrl) { - super(encodedUrl); + super(encodedUrl); } - @Key public String fields; - } + @Key + public String fields; +} diff --git a/libraries/src/main/java/com/baeldung/googlehttpclientguide/Video.java b/libraries/src/main/java/com/baeldung/googlehttpclientguide/Video.java index 62622deaf5..4d2515b202 100644 --- a/libraries/src/main/java/com/baeldung/googlehttpclientguide/Video.java +++ b/libraries/src/main/java/com/baeldung/googlehttpclientguide/Video.java @@ -1,23 +1,20 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.googlehttpclientguide; +import com.google.api.client.json.GenericJson; import com.google.api.client.util.Key; import java.util.List; -/** - * - * @author Hugo - */ - public class Video { - @Key public String id; +public class Video extends GenericJson { - @Key public List tags; + @Key + public String id; - @Key public String title; + @Key + public List tags; - @Key public String url; - } \ No newline at end of file + @Key + public String title; + + @Key + public String url; +} diff --git a/libraries/src/main/java/com/baeldung/googlehttpclientguide/VideoFeed.java b/libraries/src/main/java/com/baeldung/googlehttpclientguide/VideoFeed.java index 6b62f61924..c24f528ba7 100644 --- a/libraries/src/main/java/com/baeldung/googlehttpclientguide/VideoFeed.java +++ b/libraries/src/main/java/com/baeldung/googlehttpclientguide/VideoFeed.java @@ -1,20 +1,13 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.googlehttpclientguide; import com.google.api.client.util.Key; import java.util.List; -/** - * - * @author Hugo - */ - public class VideoFeed { - @Key public List