Search in sources :

Example 6 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.

the class CookieStoreTest method replaceCookieWhenSetOnSamePathBySameUri.

// NOTE: Similar to replaceCookieWhenSetOnSameDomainAndPath()
private void replaceCookieWhenSetOnSamePathBySameUri() {
    CookieStore store = new ThreadSafeCookieStore();
    Uri uri = Uri.create("https://foo.org/");
    store.add(uri, ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/"));
    store.add(uri, ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/"));
    store.add(uri, ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/"));
    assertTrue(store.getAll().size() == 1);
    assertTrue(store.get(uri).get(0).value().equals("VALUE3"));
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 7 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.

the class CookieStoreTest method cookieWithSameNameMustCoexistIfSetOnDifferentDomains.

private void cookieWithSameNameMustCoexistIfSetOnDifferentDomains() {
    CookieStore store = new ThreadSafeCookieStore();
    Uri uri1 = Uri.create("http://www.foo.com");
    store.add(uri1, ClientCookieDecoder.LAX.decode("ALPHA=VALUE1; Domain=www.foo.com"));
    Uri uri2 = Uri.create("http://www.bar.com");
    store.add(uri2, ClientCookieDecoder.LAX.decode("ALPHA=VALUE2; Domain=www.bar.com"));
    assertTrue(store.get(uri1).size() == 1);
    assertTrue(store.get(uri1).get(0).value().equals("VALUE1"));
    assertTrue(store.get(uri2).size() == 1);
    assertTrue(store.get(uri2).get(0).value().equals("VALUE2"));
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 8 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.

the class CookieStoreTest method ignoreQueryParametersInUri.

private void ignoreQueryParametersInUri() {
    CookieStore store = new ThreadSafeCookieStore();
    store.add(Uri.create("http://www.foo.com/bar?query1"), ClientCookieDecoder.LAX.decode("ALPHA=VALUE1; Domain=www.foo.com; path=/"));
    assertTrue(store.get(Uri.create("http://www.foo.com/bar?query2")).size() == 1);
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 9 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.

the class CookieStoreTest method replaceCookieWhenSetOnSameDomainAndPath.

private void replaceCookieWhenSetOnSameDomainAndPath() {
    CookieStore store = new ThreadSafeCookieStore();
    Uri uri = Uri.create("http://www.foo.com/bar/baz");
    store.add(uri, ClientCookieDecoder.LAX.decode("ALPHA=VALUE1; Domain=www.foo.com; path=/bar"));
    store.add(uri, ClientCookieDecoder.LAX.decode("ALPHA=VALUE2; Domain=www.foo.com; path=/bar"));
    assertTrue(store.getAll().size() == 1);
    assertTrue(store.get(uri).get(0).value().equals("VALUE2"));
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 10 with ThreadSafeCookieStore

use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.

the class DefaultAsyncHttpClientTest method testWithSharedNettyTimerShouldScheduleCookieEvictionOnlyOnce.

@Test
public void testWithSharedNettyTimerShouldScheduleCookieEvictionOnlyOnce() throws IOException {
    Timer nettyTimerMock = mock(Timer.class);
    CookieStore cookieStore = new ThreadSafeCookieStore();
    AsyncHttpClientConfig config = config().setNettyTimer(nettyTimerMock).setCookieStore(cookieStore).build();
    try (AsyncHttpClient client1 = asyncHttpClient(config)) {
        try (AsyncHttpClient client2 = asyncHttpClient(config)) {
            assertEquals(cookieStore.count(), 2);
            verify(nettyTimerMock, times(1)).newTimeout(any(CookieEvictionTask.class), anyLong(), any(TimeUnit.class));
        }
    }
}
Also used : ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) CookieStore(org.asynchttpclient.cookie.CookieStore) CookieEvictionTask(org.asynchttpclient.cookie.CookieEvictionTask) Timer(io.netty.util.Timer) TimeUnit(java.util.concurrent.TimeUnit) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Test(org.testng.annotations.Test)

Aggregations

ThreadSafeCookieStore (org.asynchttpclient.cookie.ThreadSafeCookieStore)34 CookieStore (org.asynchttpclient.cookie.CookieStore)33 Uri (org.asynchttpclient.uri.Uri)16 Test (org.testng.annotations.Test)5 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)3 Timer (io.netty.util.Timer)3 TimeUnit (java.util.concurrent.TimeUnit)3 CookieEvictionTask (org.asynchttpclient.cookie.CookieEvictionTask)3 Sets (com.google.common.collect.Sets)2 ClientCookieDecoder (io.netty.handler.codec.http.cookie.ClientCookieDecoder)2 ClientCookieEncoder (io.netty.handler.codec.http.cookie.ClientCookieEncoder)2 Cookie (io.netty.handler.codec.http.cookie.Cookie)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Assert.assertTrue (org.testng.Assert.assertTrue)2 AfterClass (org.testng.annotations.AfterClass)2 BeforeClass (org.testng.annotations.BeforeClass)2