Merge pull request #10217 from eugenp/update-httpclient
add additional property for httpclient v.4.5
This commit is contained in:
commit
bfcbaf886a
|
@ -4,12 +4,13 @@ import org.apache.http.client.CookieStore;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
import org.apache.http.client.protocol.HttpClientContext;
|
||||||
|
import org.apache.http.cookie.ClientCookie;
|
||||||
import org.apache.http.cookie.Cookie;
|
import org.apache.http.cookie.Cookie;
|
||||||
import org.apache.http.impl.client.BasicCookieStore;
|
import org.apache.http.impl.client.BasicCookieStore;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.impl.cookie.BasicClientCookie;
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ public class HttpClientGettingCookieValueUnitTest {
|
||||||
BasicCookieStore cookieStore = new BasicCookieStore();
|
BasicCookieStore cookieStore = new BasicCookieStore();
|
||||||
BasicClientCookie cookie = new BasicClientCookie("custom_cookie", "test_value");
|
BasicClientCookie cookie = new BasicClientCookie("custom_cookie", "test_value");
|
||||||
cookie.setDomain("baeldung.com");
|
cookie.setDomain("baeldung.com");
|
||||||
|
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");
|
||||||
cookie.setPath("/");
|
cookie.setPath("/");
|
||||||
cookieStore.addCookie(cookie);
|
cookieStore.addCookie(cookie);
|
||||||
return cookieStore;
|
return cookieStore;
|
||||||
|
|
|
@ -302,7 +302,7 @@
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<wiremock.version>2.5.1</wiremock.version>
|
<wiremock.version>2.5.1</wiremock.version>
|
||||||
<httpcore.version>4.4.11</httpcore.version>
|
<httpcore.version>4.4.11</httpcore.version>
|
||||||
<httpclient.version>4.5.8</httpclient.version> <!-- 4.3.6 --> <!-- 4.4-beta1 -->
|
<httpclient.version>4.5.8</httpclient.version>
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
package com.baeldung.httpclient.sec;
|
package com.baeldung.httpclient.sec;
|
||||||
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.protocol.HttpClientContext;
|
import org.apache.http.client.protocol.HttpClientContext;
|
||||||
|
import org.apache.http.cookie.ClientCookie;
|
||||||
import org.apache.http.impl.client.BasicCookieStore;
|
import org.apache.http.impl.client.BasicCookieStore;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
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 com.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;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -26,6 +30,8 @@ public class HttpClientCookieLiveTest {
|
||||||
|
|
||||||
private CloseableHttpResponse response;
|
private CloseableHttpResponse response;
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(HttpClientCookieLiveTest.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public final void before() {
|
public final void before() {
|
||||||
instance = HttpClientBuilder.create().build();
|
instance = HttpClientBuilder.create().build();
|
||||||
|
@ -54,11 +60,15 @@ public class HttpClientCookieLiveTest {
|
||||||
final BasicCookieStore cookieStore = new BasicCookieStore();
|
final BasicCookieStore cookieStore = new BasicCookieStore();
|
||||||
final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234");
|
final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234");
|
||||||
cookie.setDomain(".github.com");
|
cookie.setDomain(".github.com");
|
||||||
|
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");
|
||||||
|
|
||||||
cookie.setPath("/");
|
cookie.setPath("/");
|
||||||
cookieStore.addCookie(cookie);
|
cookieStore.addCookie(cookie);
|
||||||
final HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
|
|
||||||
|
|
||||||
final HttpGet request = new HttpGet("http://www.github.com");
|
DefaultHttpClient client = new DefaultHttpClient();
|
||||||
|
client.setCookieStore(cookieStore);
|
||||||
|
|
||||||
|
final HttpGet request = new HttpGet("https://www.github.com");
|
||||||
|
|
||||||
response = (CloseableHttpResponse) client.execute(request);
|
response = (CloseableHttpResponse) client.execute(request);
|
||||||
|
|
||||||
|
@ -70,6 +80,7 @@ public class HttpClientCookieLiveTest {
|
||||||
final BasicCookieStore cookieStore = new BasicCookieStore();
|
final BasicCookieStore cookieStore = new BasicCookieStore();
|
||||||
final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234");
|
final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234");
|
||||||
cookie.setDomain(".github.com");
|
cookie.setDomain(".github.com");
|
||||||
|
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");
|
||||||
cookie.setPath("/");
|
cookie.setPath("/");
|
||||||
cookieStore.addCookie(cookie);
|
cookieStore.addCookie(cookie);
|
||||||
instance = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
|
instance = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
|
||||||
|
|
Loading…
Reference in New Issue