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);
}
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);
}
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));
}
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));
}
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
}
}
Aggregations