This commit is contained in:
Thai Nguyen
2016-10-18 13:30:03 +07:00
143 changed files with 1334 additions and 802 deletions
+2 -1
View File
@@ -1 +1,2 @@
### Relevant Articles:
- [Java Annotation Processing and Creating a Builder](http://www.baeldung.com/java-annotation-processing-builder)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf)
+3
View File
@@ -0,0 +1,3 @@
### Relevant Articles:
- [AssertJ’s Java 8 Features](http://www.baeldung.com/assertJ-java-8-features)
- [AssertJ for Guava](http://www.baeldung.com/assertJ-for-guava)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to AutoValue](http://www.baeldung.com/introduction-to-autovalue)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro)
@@ -0,0 +1,2 @@
### Relevant Articles:
- [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums)
@@ -1 +1,2 @@
### Relevant Artiles:
- [Filtering a Stream of Optionals in Java](http://www.baeldung.com/java-filter-stream-of-optional)
+5
View File
@@ -13,3 +13,8 @@
- [Java – Write to File](http://www.baeldung.com/java-write-to-file)
- [Java Scanner](http://www.baeldung.com/java-scanner)
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer)
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
- [MD5 Hashing in Java](http://www.baeldung.com/java-md5)
- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist)
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
+282 -172
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
package org.baeldung.executable;
import javax.swing.JOptionPane;
public class ExecutableMavenJar {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "It worked!", "Executable Jar with Maven", 1);
}
}
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Wiring in Spring: @Autowired, @Resource and @Inject](http://www.baeldung.com/spring-annotations-resource-inject-autowire)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [A Guide to Mapping With Dozer](http://www.baeldung.com/dozer)
+3
View File
@@ -3,3 +3,6 @@
This is the implementation of a [spring-hypermedia-api][1] client using Feign.
[1]: https://github.com/eugenp/spring-hypermedia-api
###Relevant Articles:
- [Intro to Feign](http://www.baeldung.com/intro-to-feign)
+2 -1
View File
@@ -1 +1,2 @@
### Relevant Articles:
- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Intro to Gatling](http://www.baeldung.com/introduction-to-gatling)
+6
View File
@@ -0,0 +1,6 @@
## Performance of Gson and Jackson
Standalone java programs to measure the performance of both JSON APIs based on file size and object graph complexity.
###Relevant Articles:
- [Jackson vs Gson: A Quick Look At Performance](http://www.baeldung.com/jackson-gson-performance)
+1
View File
@@ -5,3 +5,4 @@
### Relevant Articles:
- [Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide)
- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson)
+1
View File
@@ -15,3 +15,4 @@
- [Guava – Lists](http://www.baeldung.com/guava-lists)
- [Guava – Sets](http://www.baeldung.com/guava-sets)
- [Guava – Maps](http://www.baeldung.com/guava-maps)
- [Guava Set + Function = Map](http://www.baeldung.com/guava-set-function-map-tutorial)
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Testing with Hamcrest](http://www.baeldung.com/java-junit-hamcrest-guide)
@@ -0,0 +1,3 @@
### Relevant Articles:
- [Cachable Static Assets with Spring MVC](http://www.baeldung.com/cachable-static-assets-with-spring-mvc)
- [Minification of JS and CSS Assets with Maven](http://www.baeldung.com/maven-minification-of-js-and-css-assets)
@@ -33,7 +33,7 @@ import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.junit.Test;
public class HttpAsyncClientTest {
public class HttpAsyncClientLiveTest {
private static final String HOST = "http://www.google.com";
private static final String HOST_WITH_SSL = "https://mms.nw.ru/";
@@ -1,188 +0,0 @@
package org.baeldung.httpclient;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.util.EntityUtils;
import org.junit.Ignore;
import org.junit.Test;
public class SandboxTest {
// original example
@Ignore
@Test
public final void whenInterestingDigestAuthScenario_then401UnAuthorized() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException {
final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http");
// set up the credentials to run agains the server
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd"));
// We need a first run to get a 401 to seed the digest auth
// Make a client using those creds
final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
// And make a call to the URL we are after
final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd");
// Create a context to use
final HttpClientContext context = HttpClientContext.create();
// Get a response from the sever (expect a 401!)
final HttpResponse authResponse = client.execute(targetHost, httpget, context);
// Pull out the auth header that came back from the server
final Header challenge = authResponse.getHeaders("WWW-Authenticate")[0];
// Lets use a digest scheme to solve it
final DigestScheme digest = new DigestScheme();
digest.processChallenge(challenge);
// Make a header with the solution based upon user/password and what the digest got out of the initial 401 reponse
final Header solution = digest.authenticate(new UsernamePasswordCredentials("user", "passwd"), httpget, context);
// Need an auth cache to use the new digest we made
final AuthCache authCache = new BasicAuthCache();
authCache.put(targetHost, digest);
// Add the authCache and thus solved digest to the context
context.setAuthCache(authCache);
// Pimp up our http get with the solved header made by the digest
httpget.addHeader(solution);
// use it!
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + targetHost);
for (int i = 0; i < 3; i++) {
final CloseableHttpResponse responseGood = client.execute(targetHost, httpget, context);
try {
System.out.println("----------------------------------------");
System.out.println(responseGood.getStatusLine());
System.out.println(EntityUtils.toString(responseGood.getEntity()));
} finally {
responseGood.close();
}
}
}
@Test
public final void whenInterestingDigestAuthScenario_then200OK() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException {
final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http");
// set up the credentials to run agains the server
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd"));
// This endpoint need fake cookie to work properly
final CookieStore cookieStore = new BasicCookieStore();
final BasicClientCookie cookie = new BasicClientCookie("fake", "fake_value");
cookie.setDomain("httpbin.org");
cookie.setPath("/");
cookieStore.addCookie(cookie);
// Make a client using those creds
final CloseableHttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build();
// And make a call to the URL we are after
final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd");
// Create a context to use
final HttpClientContext context = HttpClientContext.create();
// Get a response from the sever (401 implicitly)
final HttpResponse authResponse = client.execute(targetHost, httpget, context);
assertEquals(200, authResponse.getStatusLine().getStatusCode());
// HttpClient will use cached digest parameters for future requests
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + targetHost);
for (int i = 0; i < 3; i++) {
final CloseableHttpResponse responseGood = client.execute(targetHost, httpget, context);
try {
System.out.println("----------------------------------------");
System.out.println(responseGood.getStatusLine());
assertEquals(200, responseGood.getStatusLine().getStatusCode());
} finally {
responseGood.close();
}
}
client.close();
}
// This test needs module spring-security-rest-digest-auth to be running
@Test
public final void whenWeKnowDigestParameters_thenNo401Status() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException {
final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user1", "user1Pass"));
final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
final HttpGet httpget = new HttpGet("http://localhost:8080/spring-security-rest-digest-auth/api/foos/1");
final HttpClientContext context = HttpClientContext.create();
// == make it preemptive
final AuthCache authCache = new BasicAuthCache();
final DigestScheme digestAuth = new DigestScheme();
digestAuth.overrideParamter("realm", "Custom Realm Name");
digestAuth.overrideParamter("nonce", "nonce value goes here");
authCache.put(targetHost, digestAuth);
context.setAuthCache(authCache);
// == end
System.out.println("Executing The Request knowing the digest parameters ==== ");
final HttpResponse authResponse = client.execute(targetHost, httpget, context);
assertEquals(200, authResponse.getStatusLine().getStatusCode());
client.close();
}
// This test needs module spring-security-rest-digest-auth to be running
@Test
public final void whenDoNotKnowParameters_thenOnlyOne401() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException {
final HttpClientContext context = HttpClientContext.create();
final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user1", "user1Pass"));
final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
final HttpGet httpget = new HttpGet("http://localhost:8080/spring-security-rest-digest-auth/api/foos/1");
System.out.println("Executing The Request NOT knowing the digest parameters ==== ");
final HttpResponse tempResponse = client.execute(targetHost, httpget, context);
assertEquals(200, tempResponse.getStatusLine().getStatusCode());
for (int i = 0; i < 3; i++) {
System.out.println("No more Challenges or 401");
final CloseableHttpResponse authResponse = client.execute(targetHost, httpget, context);
assertEquals(200, authResponse.getStatusLine().getStatusCode());
authResponse.close();
}
client.close();
}
}
@@ -10,9 +10,11 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Test;
@@ -58,4 +60,14 @@ public class HttpClientSandboxLiveTest {
System.out.println(response.getStatusLine());
}
@Test
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws ClientProtocolException, IOException {
final CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
final HttpGet httpGet = new HttpGet("https://sesar3.geoinfogeochem.org/sample/igsn/ODP000002");
httpGet.setHeader("Accept", "application/xml");
response = httpClient.execute(httpGet);
}
}
@@ -36,7 +36,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class HttpClientConnectionManagementTest {
public class HttpClientConnectionManagementLiveTest {
private static final String SERVER1 = "http://www.petrikainulainen.net/";
private static final String SERVER7 = "http://www.baeldung.com/";
+3
View File
@@ -0,0 +1,3 @@
### Relevant Articles:
- [Hystrix Integration with Existing Spring Application](http://www.baeldung.com/hystrix-integration-with-spring-aop)
- [Introduction to Hystrix](http://www.baeldung.com/introduction-to-hystrix)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to Immutables](http://www.baeldung.com/immutables)
+5
View File
@@ -19,3 +19,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not)
- [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations)
- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model)
- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson)
- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial)
- [XML Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-xml-serialization-and-deserialization)
- [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations)
- [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance)
+2
View File
@@ -0,0 +1,2 @@
### Relevant Articles:
- [Scheduling in Java EE](http://www.baeldung.com/scheduling-in-java-enterprise-edition)

Some files were not shown because too many files have changed in this diff Show More