11package com .baeldung .httpclient .sec ;
22
3- import org .apache .http .client .HttpClient ;
43import org .apache .http .client .methods .CloseableHttpResponse ;
54import org .apache .http .client .methods .HttpGet ;
65import org .apache .http .client .protocol .HttpClientContext ;
6+ import org .apache .http .cookie .ClientCookie ;
77import org .apache .http .impl .client .BasicCookieStore ;
88import org .apache .http .impl .client .CloseableHttpClient ;
9+ import org .apache .http .impl .client .DefaultHttpClient ;
910import org .apache .http .impl .client .HttpClientBuilder ;
1011import org .apache .http .impl .cookie .BasicClientCookie ;
1112import org .apache .http .protocol .BasicHttpContext ;
1213import org .apache .http .protocol .HttpContext ;
1314import com .baeldung .httpclient .ResponseUtil ;
15+
1416import org .junit .After ;
1517import org .junit .Before ;
1618import org .junit .Test ;
19+ import org .slf4j .Logger ;
20+ import org .slf4j .LoggerFactory ;
1721
1822import java .io .IOException ;
1923
@@ -25,6 +29,8 @@ public class HttpClientCookieLiveTest {
2529 private CloseableHttpClient instance ;
2630
2731 private CloseableHttpResponse response ;
32+
33+ private static Logger log = LoggerFactory .getLogger (HttpClientCookieLiveTest .class );
2834
2935 @ Before
3036 public final void before () {
@@ -54,11 +60,15 @@ public final void givenUsingDeprecatedApi_whenSettingCookiesOnTheHttpClient_then
5460 final BasicCookieStore cookieStore = new BasicCookieStore ();
5561 final BasicClientCookie cookie = new BasicClientCookie ("JSESSIONID" , "1234" );
5662 cookie .setDomain (".github.com" );
63+ cookie .setAttribute (ClientCookie .DOMAIN_ATTR , "true" );
64+
5765 cookie .setPath ("/" );
5866 cookieStore .addCookie (cookie );
59- final HttpClient client = HttpClientBuilder .create ().setDefaultCookieStore (cookieStore ).build ();
60-
61- final HttpGet request = new HttpGet ("http://www.github.com" );
67+
68+ DefaultHttpClient client = new DefaultHttpClient ();
69+ client .setCookieStore (cookieStore );
70+
71+ final HttpGet request = new HttpGet ("https://www.github.com" );
6272
6373 response = (CloseableHttpResponse ) client .execute (request );
6474
@@ -70,6 +80,7 @@ public final void whenSettingCookiesOnTheHttpClient_thenCookieSentCorrectly() th
7080 final BasicCookieStore cookieStore = new BasicCookieStore ();
7181 final BasicClientCookie cookie = new BasicClientCookie ("JSESSIONID" , "1234" );
7282 cookie .setDomain (".github.com" );
83+ cookie .setAttribute (ClientCookie .DOMAIN_ATTR , "true" );
7384 cookie .setPath ("/" );
7485 cookieStore .addCookie (cookie );
7586 instance = HttpClientBuilder .create ().setDefaultCookieStore (cookieStore ).build ();
0 commit comments