BAEL-1174: A Quick Guide to Spring Cloud Consul

This commit is contained in:
Jose Carvajal
2017-11-30 12:01:23 +01:00
881 changed files with 10705 additions and 802 deletions
+7 -2
View File
@@ -39,7 +39,6 @@
- [Introduction to Apache Commons CSV](http://www.baeldung.com/apache-commons-csv)
- [Difference Between Two Dates in Java](http://www.baeldung.com/java-date-difference)
- [Introduction to NoException](http://www.baeldung.com/no-exception)
- [Introduction to FunctionalJava](http://www.baeldung.com/functional-java)
- [Apache Commons IO](http://www.baeldung.com/apache-commons-io)
- [Introduction to Conflict-Free Replicated Data Types](http://www.baeldung.com/java-conflict-free-replicated-data-types)
- [Introduction to javax.measure](http://www.baeldung.com/javax-measure)
@@ -53,7 +52,13 @@
- [Using Pairs in Java](http://www.baeldung.com/java-pairs)
- [Apache Commons Collections Bag](http://www.baeldung.com/apache-commons-bag)
- [Introduction to Caffeine](http://www.baeldung.com/java-caching-caffeine)
+-[Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
- [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
- [Introduction To Docx4J](http://www.baeldung.com/docx4j)
- [Introduction to StreamEx](http://www.baeldung.com/streamex)
- [Introduction to BouncyCastle with Java](http://www.baeldung.com/java-bouncy-castle)
- [Intro to JDO Queries 2/2](http://www.baeldung.com/jdo-queries)
- [Guide to google-http-client](http://www.baeldung.com/google-http-client)
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.
+16
View File
@@ -622,6 +622,21 @@
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>${googleclient.version}</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>${googleclient.version}</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<version>${googleclient.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
@@ -639,6 +654,7 @@
</repository>
</repositories>
<properties>
<googleclient.version>1.23.0</googleclient.version>
<crdt.version>0.1.0</crdt.version>
<multiverse.version>0.7.0</multiverse.version>
<cglib.version>3.2.4</cglib.version>
@@ -0,0 +1,65 @@
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.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
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.jackson2.JacksonFactory;
import com.google.api.client.util.ExponentialBackOff;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class GitHubExample {
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
//static final HttpTransport HTTP_TRANSPORT = new ApacheHttpTransport();
static final JsonFactory JSON_FACTORY = new JacksonFactory();
//static final JsonFactory JSON_FACTORY = new GsonFactory();
private static void run() throws Exception {
HttpRequestFactory requestFactory
= HTTP_TRANSPORT.createRequestFactory(
(HttpRequest request) -> {
request.setParser(new JsonObjectParser(JSON_FACTORY));
});
GitHubUrl url = new GitHubUrl("https://api.github.com/users");
url.per_page = 10;
url.page = 1;
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));
Type type = new TypeToken<List<User>>() {}.getType();
List<User> users = (List<User>)request.execute().parseAs(type);
System.out.println(users);
url.appendRawPath("/eugenp");
request = requestFactory.buildGetRequest(url);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<HttpResponse> responseFuture = request.executeAsync(executor);
User eugen = responseFuture.get().parseAs(User.class);
System.out.println(eugen);
executor.shutdown();
}
public static void main(String[] args) {
try {
run();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
@@ -0,0 +1,18 @@
package com.baeldung.googlehttpclientguide;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.util.Key;
public class GitHubUrl extends GenericUrl{
public GitHubUrl(String encodedUrl) {
super(encodedUrl);
}
@Key
public int per_page;
@Key
public int page;
}
@@ -0,0 +1,77 @@
package com.baeldung.googlehttpclientguide;
import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key;
public class User extends GenericJson {
@Key
private String login;
@Key
private long id;
@Key
private String url;
@Key
private String company;
@Key
private String blog;
@Key
private String email;
@Key("subscriptions_url")
private String subscriptionsUrl;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getBlog() {
return blog;
}
public void setBlog(String blog) {
this.blog = blog;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User{" + "login=" + login + ", id=" + id + ", url=" + url + ", company=" + company + ", blog=" + blog + ", email=" + email + '}';
}
}
@@ -0,0 +1,10 @@
# Properties file which configures the operation of the JDK logging facility.
# The system will look for this config file to be specified as a system property:
# -Djava.util.logging.config.file=${project_loc:dailymotion-simple-cmdline-sample}/logging.properties
# Set up the console handler (uncomment "level" to show more fine-grained messages)
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
# Set up logging of HTTP requests and responses (uncomment "level" to show)
com.google.api.client.http.level = ALL
@@ -51,7 +51,6 @@ public class MemberStatusIntegrationTest {
/**
* This test should fail, comment out <code>@Ignore</code> to see how failed test can be reflected in Serenity report. <br/>
* Remember to add <code>&lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt;</code> under maven-surefire-plugin configuration.
*/
@Test
@Ignore