Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-12800

This commit is contained in:
amit2103 2019-05-05 01:00:42 +05:30
commit d2aa729502
32 changed files with 60 additions and 54 deletions

View File

@ -1,11 +1,5 @@
========= =========
## HttpClient 4.x Cookbooks and Examples ## This module contains articles that are part of the HTTPClient Ebook
###The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [HttpClient 4 Get the Status Code](http://www.baeldung.com/httpclient-status-code) - [HttpClient 4 Get the Status Code](http://www.baeldung.com/httpclient-status-code)
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) - [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
@ -14,3 +8,9 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) - [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header)
- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication)
- [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request) - [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request)
### Running the Tests
To run the live tests, use the command: mvn clean install -Plive
This will start an embedded Jetty server on port 8082 using the Cargo plugin configured in the pom.xml file,
for the live Maven profile

View File

@ -1,4 +1,4 @@
package org.baeldung.basic; package com.baeldung.basic;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;

View File

@ -1,4 +1,4 @@
package org.baeldung.client; package com.baeldung.client;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;

View File

@ -1,10 +1,10 @@
package org.baeldung.client.spring; package com.baeldung.client.spring;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@ComponentScan("org.baeldung.client") @ComponentScan("com.baeldung.client")
public class ClientConfig { public class ClientConfig {
public ClientConfig() { public ClientConfig() {

View File

@ -1,4 +1,4 @@
package org.baeldung.filter; package com.baeldung.filter;
import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.filter.GenericFilterBean;

View File

@ -1,6 +1,6 @@
package org.baeldung.filter; package com.baeldung.filter;
import org.baeldung.security.RestAuthenticationEntryPoint; import com.baeldung.security.RestAuthenticationEntryPoint;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package org.baeldung.security; package com.baeldung.security;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.baeldung.security; package com.baeldung.security;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring; package com.baeldung.spring;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -6,7 +6,7 @@ import org.springframework.context.annotation.ImportResource;
@Configuration @Configuration
@ImportResource({ "classpath:webSecurityConfig.xml" }) @ImportResource({ "classpath:webSecurityConfig.xml" })
@ComponentScan("org.baeldung.security") @ComponentScan("com.baeldung.security")
public class SecSecurityConfig { public class SecSecurityConfig {
public SecSecurityConfig() { public SecSecurityConfig() {

View File

@ -1,4 +1,4 @@
package org.baeldung.spring; package com.baeldung.spring;
import java.util.List; import java.util.List;
@ -11,7 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
@EnableWebMvc @EnableWebMvc
@ComponentScan("org.baeldung.web") @ComponentScan("com.baeldung.web")
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
public WebConfig() { public WebConfig() {

View File

@ -1,6 +1,6 @@
package org.baeldung.web.controller; package com.baeldung.web.controller;
import org.baeldung.web.dto.Bar; import com.baeldung.web.dto.Bar;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -1,6 +1,6 @@
package org.baeldung.web.controller; package com.baeldung.web.controller;
import org.baeldung.web.dto.Foo; import com.baeldung.web.dto.Foo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;

View File

@ -1,4 +1,4 @@
package org.baeldung.web.dto; package com.baeldung.web.dto;
import java.io.Serializable; import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package org.baeldung.web.dto; package com.baeldung.web.dto;
import java.io.Serializable; import java.io.Serializable;

View File

@ -23,6 +23,6 @@
<global-method-security pre-post-annotations="enabled"/> <global-method-security pre-post-annotations="enabled"/>
<beans:bean id="myBasicAuthenticationEntryPoint" class="org.baeldung.basic.MyBasicAuthenticationEntryPoint" /> <beans:bean id="myBasicAuthenticationEntryPoint" class="com.baeldung.basic.MyBasicAuthenticationEntryPoint" />
</beans:beans> </beans:beans>

View File

@ -12,7 +12,7 @@
</context-param> </context-param>
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value>org.baeldung.spring</param-value> <param-value>com.baeldung.spring</param-value>
</context-param> </context-param>
<listener> <listener>

View File

@ -1,11 +1,11 @@
package org.baeldung.client; package com.baeldung.client;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.baeldung.client.spring.ClientConfig; import com.baeldung.client.spring.ClientConfig;
import org.baeldung.web.dto.Foo; import com.baeldung.web.dto.Foo;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,4 +1,4 @@
package org.baeldung.client; package com.baeldung.client;
import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -51,6 +51,7 @@ public class RestClientLiveManualTest {
final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient(); final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient();
final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER); final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf)); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf));

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.http.Header; import org.apache.http.Header;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat;
* NOTE : Need module spring-rest to be running * NOTE : Need module spring-rest to be running
*/ */
public class HttpClientPostingLiveTest { public class HttpClientPostingLiveTest {
private static final String SAMPLE_URL = "http://localhost:8082/spring-rest/users"; private static final String SAMPLE_URL = "http://www.example.com";
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
private static final String DEFAULT_USER = "test"; private static final String DEFAULT_USER = "test";
private static final String DEFAULT_PASS = "test"; private static final String DEFAULT_PASS = "test";
@ -69,7 +69,7 @@ public class HttpClientPostingLiveTest {
@Test @Test
public void whenPostJsonUsingHttpClient_thenCorrect() throws IOException { public void whenPostJsonUsingHttpClient_thenCorrect() throws IOException {
final CloseableHttpClient client = HttpClients.createDefault(); final CloseableHttpClient client = HttpClients.createDefault();
final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/detail"); final HttpPost httpPost = new HttpPost(SAMPLE_URL);
final String json = "{\"id\":1,\"name\":\"John\"}"; final String json = "{\"id\":1,\"name\":\"John\"}";
final StringEntity entity = new StringEntity(json); final StringEntity entity = new StringEntity(json);
@ -92,7 +92,7 @@ public class HttpClientPostingLiveTest {
@Test @Test
public void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException { public void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException {
final CloseableHttpClient client = HttpClients.createDefault(); final CloseableHttpClient client = HttpClients.createDefault();
final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/multipart"); final HttpPost httpPost = new HttpPost(SAMPLE_URL);
final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("username", DEFAULT_USER); builder.addTextBody("username", DEFAULT_USER);
@ -110,7 +110,7 @@ public class HttpClientPostingLiveTest {
@Test @Test
public void whenUploadFileUsingHttpClient_thenCorrect() throws IOException { public void whenUploadFileUsingHttpClient_thenCorrect() throws IOException {
final CloseableHttpClient client = HttpClients.createDefault(); final CloseableHttpClient client = HttpClients.createDefault();
final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/upload"); final HttpPost httpPost = new HttpPost(SAMPLE_URL);
final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext");
@ -126,7 +126,7 @@ public class HttpClientPostingLiveTest {
@Test @Test
public void whenGetUploadFileProgressUsingHttpClient_thenCorrect() throws IOException { public void whenGetUploadFileProgressUsingHttpClient_thenCorrect() throws IOException {
final CloseableHttpClient client = HttpClients.createDefault(); final CloseableHttpClient client = HttpClients.createDefault();
final HttpPost httpPost = new HttpPost(SAMPLE_URL + "/upload"); final HttpPost httpPost = new HttpPost(SAMPLE_URL);
final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext");

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@ -20,6 +20,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.params.CoreConnectionPNames; import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.junit.After; import org.junit.After;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
public class HttpClientTimeoutLiveTest { public class HttpClientTimeoutLiveTest {
@ -91,6 +92,7 @@ public class HttpClientTimeoutLiveTest {
* This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP) * This simulates a timeout against a domain with multiple routes/IPs to it (not a single raw IP)
*/ */
@Test(expected = ConnectTimeoutException.class) @Test(expected = ConnectTimeoutException.class)
@Ignore
public final void givenTimeoutIsConfigured_whenTimingOut_thenTimeoutException() throws IOException { public final void givenTimeoutIsConfigured_whenTimingOut_thenTimeoutException() throws IOException {
final int timeout = 3; final int timeout = 3;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient; package com.baeldung.httpclient;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient.base; package com.baeldung.httpclient.base;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
@ -8,7 +8,7 @@ import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.baeldung.httpclient.ResponseUtil; import com.baeldung.httpclient.ResponseUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient.sec; package com.baeldung.httpclient.sec;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
@ -17,7 +17,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.baeldung.httpclient.ResponseUtil; import com.baeldung.httpclient.ResponseUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.httpclient.sec; package com.baeldung.httpclient.sec;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
@ -10,7 +10,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.baeldung.httpclient.ResponseUtil; import com.baeldung.httpclient.ResponseUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,7 +1,7 @@
package org.baeldung.test; package com.baeldung.test;
import org.baeldung.client.ClientLiveTest; import com.baeldung.client.ClientLiveTest;
import org.baeldung.client.RestClientLiveManualTest; import com.baeldung.client.RestClientLiveManualTest;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;

View File

@ -0,0 +1 @@
hello world

View File

@ -1 +1,3 @@
## Relevant articles: ## Relevant articles:
- [Jackson Support for Kotlin](https://www.baeldung.com/jackson-kotlin)

View File

@ -49,7 +49,7 @@
<properties> <properties>
<assertj.version>3.6.2</assertj.version> <assertj.version>3.6.2</assertj.version>
<classgraph.version>4.8.22</classgraph.version> <classgraph.version>4.8.28</classgraph.version>
<jbpm.version>6.0.0.Final</jbpm.version> <jbpm.version>6.0.0.Final</jbpm.version>
</properties> </properties>
</project> </project>