Search in sources :

Example 51 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project UltimateAndroid by cymcsg.

the class HttpUtilsAsync method getUseCookie.

public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) Iterator(java.util.Iterator) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project UltimateAndroid by cymcsg.

the class HttpUtilsAsync method postUseCookie.

public static void postUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) Iterator(java.util.Iterator) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) HashMap(java.util.HashMap) Map(java.util.Map)

Example 53 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainHostPortMatch.

@Test
public void testDomainHostPortMatch() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("myhost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain("myhost");
    try {
        h.match(cookie, null);
        Assert.fail("IllegalArgumentException should have been thrown, since origin is null.");
    } catch (final IllegalArgumentException ex) {
    // expected
    }
    cookie.setDomain(null);
    Assert.assertFalse(h.match(cookie, origin));
    cookie.setDomain("otherhost");
    Assert.assertFalse(h.match(cookie, origin));
    cookie.setDomain("myhost");
    Assert.assertTrue(h.match(cookie, origin));
    cookie.setDomain("myhost:80");
    Assert.assertTrue(h.match(cookie, origin));
    cookie.setDomain("myhost:8080");
    Assert.assertFalse(h.match(cookie, origin));
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 54 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainMatch2.

@Test
public void testDomainMatch2() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain(".somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 55 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainInvalidInput.

@Test
public void testDomainInvalidInput() throws Exception {
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    try {
        h.match(null, null);
        Assert.fail("IllegalArgumentException must have been thrown");
    } catch (final IllegalArgumentException ex) {
    // expected
    }
    try {
        h.match(new BasicClientCookie("name", "value"), null);
        Assert.fail("IllegalArgumentException must have been thrown");
    } catch (final IllegalArgumentException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Test(org.junit.Test)

Aggregations

BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)88 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)36 Test (org.junit.Test)24 HttpResponse (org.apache.http.HttpResponse)19 Cookie (org.apache.http.cookie.Cookie)17 HttpClient (org.apache.http.client.HttpClient)15 HttpGet (org.apache.http.client.methods.HttpGet)15 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)15 Map (java.util.Map)14 RequestConfig (org.apache.http.client.config.RequestConfig)13 HttpPost (org.apache.http.client.methods.HttpPost)9 CookieAttributeHandler (org.apache.http.cookie.CookieAttributeHandler)9 CookieOrigin (org.apache.http.cookie.CookieOrigin)9 URL (java.net.URL)8 HttpEntity (org.apache.http.HttpEntity)8 CookieStore (org.apache.http.client.CookieStore)8 IOException (java.io.IOException)7 Date (java.util.Date)7 ClientCookie (org.apache.http.cookie.ClientCookie)7 HashMap (java.util.HashMap)6