From 985d8df0885acf35ccc0c94701d9a2ef791c78cb Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 29 Oct 2020 15:16:29 +0200 Subject: [PATCH] add additional property for httpclient v.4.5 --- .../HttpClientGettingCookieValueUnitTest.java | 4 +++- httpclient-simple/pom.xml | 2 +- .../sec/HttpClientCookieLiveTest.java | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java b/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java index c3b0ef3c25..404acb3098 100644 --- a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java +++ b/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java @@ -4,12 +4,13 @@ import org.apache.http.client.CookieStore; 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.cookie.ClientCookie; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.cookie.BasicClientCookie; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,6 +48,7 @@ public class HttpClientGettingCookieValueUnitTest { BasicCookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = new BasicClientCookie("custom_cookie", "test_value"); cookie.setDomain("baeldung.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); cookie.setPath("/"); cookieStore.addCookie(cookie); return cookieStore; diff --git a/httpclient-simple/pom.xml b/httpclient-simple/pom.xml index 4b97070307..019f1af856 100644 --- a/httpclient-simple/pom.xml +++ b/httpclient-simple/pom.xml @@ -302,7 +302,7 @@ 2.5.1 4.4.11 - 4.5.8 + 4.5.8 1.6.1 diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java index 287b6e996c..75286e5b2e 100644 --- a/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/sec/HttpClientCookieLiveTest.java @@ -1,19 +1,23 @@ package com.baeldung.httpclient.sec; -import org.apache.http.client.HttpClient; 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.cookie.ClientCookie; import org.apache.http.impl.client.BasicCookieStore; 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.cookie.BasicClientCookie; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import com.baeldung.httpclient.ResponseUtil; + import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; @@ -25,6 +29,8 @@ public class HttpClientCookieLiveTest { private CloseableHttpClient instance; private CloseableHttpResponse response; + + private static Logger log = LoggerFactory.getLogger(HttpClientCookieLiveTest.class); @Before public final void before() { @@ -54,11 +60,15 @@ public class HttpClientCookieLiveTest { final BasicCookieStore cookieStore = new BasicCookieStore(); final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234"); cookie.setDomain(".github.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); + cookie.setPath("/"); 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); @@ -70,6 +80,7 @@ public class HttpClientCookieLiveTest { final BasicCookieStore cookieStore = new BasicCookieStore(); final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234"); cookie.setDomain(".github.com"); + cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); cookie.setPath("/"); cookieStore.addCookie(cookie); instance = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();