Removed comments from author, reformat

This commit is contained in:
hgomez 2017-11-05 18:36:44 -05:00
parent d936889921
commit 3db7b36662
4 changed files with 36 additions and 57 deletions

View File

@ -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; package com.baeldung.googlehttpclientguide;
import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler;
import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory; 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.HttpResponseException;
import com.google.api.client.http.HttpTransport; import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory; import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser; 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.json.jackson2.JacksonFactory;
import com.google.api.client.util.ExponentialBackOff;
/**
*
* @author Hugo
*/
public class DailyMotionExample { public class DailyMotionExample {
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
@ -29,15 +20,20 @@ public class DailyMotionExample {
private static void run() throws Exception { private static void run() throws Exception {
HttpRequestFactory requestFactory HttpRequestFactory requestFactory
= HTTP_TRANSPORT.createRequestFactory( = HTTP_TRANSPORT.createRequestFactory(
new HttpRequestInitializer() { (HttpRequest request) -> {
request.setParser(new JsonObjectParser(JSON_FACTORY));
public void initialize(HttpRequest request) { });
request.setParser(new JsonObjectParser(JSON_FACTORY));
}
});
DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/"); DailyMotionUrl url = new DailyMotionUrl("https://api.dailymotion.com/videos/");
url.fields = "id,tags,title,url"; url.fields = "id,tags,title,url";
HttpRequest request = requestFactory.buildGetRequest(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); VideoFeed videoFeed = request.execute().parseAs(VideoFeed.class);
if (videoFeed.list.isEmpty()) { if (videoFeed.list.isEmpty()) {
System.out.println("No videos found."); System.out.println("No videos found.");

View File

@ -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; package com.baeldung.googlehttpclientguide;
import com.google.api.client.http.GenericUrl; import com.google.api.client.http.GenericUrl;
import com.google.api.client.util.Key; import com.google.api.client.util.Key;
/**
* public class DailyMotionUrl extends GenericUrl {
* @author Hugo
*/
public class DailyMotionUrl extends GenericUrl {
public DailyMotionUrl(String encodedUrl) { public DailyMotionUrl(String encodedUrl) {
super(encodedUrl); super(encodedUrl);
} }
@Key public String fields; @Key
} public String fields;
}

View File

@ -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; package com.baeldung.googlehttpclientguide;
import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key; import com.google.api.client.util.Key;
import java.util.List; import java.util.List;
/** public class Video extends GenericJson {
*
* @author Hugo
*/
public class Video {
@Key public String id;
@Key public List<String> tags; @Key
public String id;
@Key public String title; @Key
public List<String> tags;
@Key public String url; @Key
} public String title;
@Key
public String url;
}

View File

@ -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; package com.baeldung.googlehttpclientguide;
import com.google.api.client.util.Key; import com.google.api.client.util.Key;
import java.util.List; import java.util.List;
/** public class VideoFeed {
*
* @author Hugo @Key
*/ public List<Video> list;
public class VideoFeed {
@Key public List<Video> list;
@Key("has_more") @Key("has_more")
public boolean hasMore; public boolean hasMore;
} }