Search in sources :

Example 96 with HttpCookie

use of java.net.HttpCookie in project j2objc by google.

the class CookiesTest method testCookieStoreRemoveRequiresUri.

public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieStore.add(new URI("http://android.com/source/"), cookieA);
    assertFalse(// RI6 fails this
    "Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 97 with HttpCookie

use of java.net.HttpCookie in project jphp by jphp-compiler.

the class HttpClientExtension method arrayToCookie.

public static HttpCookie arrayToCookie(ArrayMemory array) {
    Memory name = array.valueOfIndex("name");
    if (!name.toBoolean()) {
        throw new IllegalArgumentException("Cookie name is empty");
    }
    HttpCookie cookie = new HttpCookie(name.toString(), array.valueOfIndex("value").toString());
    if (array.containsKey("domain")) {
        cookie.setDomain(array.valueOfIndex("domain").toString());
    }
    if (array.containsKey("path")) {
        cookie.setPath(array.valueOfIndex("path").toString());
    }
    if (array.containsKey("secure")) {
        cookie.setSecure(array.valueOfIndex("secure").toBoolean());
    }
    if (array.containsKey("maxAge")) {
        cookie.setMaxAge(array.valueOfIndex("maxAge").toLong());
    }
    if (array.containsKey("comment")) {
        cookie.setComment(array.valueOfIndex("comment").toString());
    }
    if (array.containsKey("discard")) {
        cookie.setDiscard(array.valueOfIndex("discard").toBoolean());
    }
    if (array.containsKey("ports")) {
        cookie.setPortlist(array.valueOfIndex("ports").toString());
    }
    if (array.containsKey("version")) {
        cookie.setVersion(array.valueOfIndex("version").toInteger());
    }
    if (array.containsKey("httpOnly")) {
        cookie.setHttpOnly(array.valueOfIndex("httpOnly").toBoolean());
    }
    return cookie;
}
Also used : Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) HttpCookie(java.net.HttpCookie)

Example 98 with HttpCookie

use of java.net.HttpCookie in project android-oss by kickstarter.

the class RefTagUtilsTest method testBuildCookieForRefTagAndProject_WithMalformedUrl.

@Test
public void testBuildCookieForRefTagAndProject_WithMalformedUrl() {
    final Project.Urls.Web webUrls = ProjectFactory.project().urls().web().toBuilder().project("such:\\bad^<data").build();
    final Project.Urls urls = ProjectFactory.project().urls().toBuilder().web(webUrls).build();
    final Project project = ProjectFactory.project().toBuilder().urls(urls).build();
    final RefTag refTag = RefTag.category();
    final HttpCookie cookie = RefTagUtils.buildCookieWithRefTagAndProject(refTag, project);
    assertNull(cookie);
}
Also used : Project(com.kickstarter.models.Project) RefTag(com.kickstarter.libs.RefTag) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Example 99 with HttpCookie

use of java.net.HttpCookie in project android-oss by kickstarter.

the class RefTagUtilsTest method testFindRefTagCookieForProject_WhenCookieExists.

@Test
public void testFindRefTagCookieForProject_WhenCookieExists() {
    final CookieManager cookieManager = new CookieManager();
    final CookieStore cookieStore = cookieManager.getCookieStore();
    final Project project = ProjectFactory.project();
    final RefTag refTag = RefTag.recommended();
    // set and retrieve the cookie
    cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
    final HttpCookie cookie = RefTagUtils.findRefTagCookieForProject(project, cookieManager, sharedPreferences);
    assertNotNull(cookie);
    assertEquals(RefTagUtils.cookieNameForProject(project), cookie.getName());
    assertEquals(RefTagUtils.cookieValueForRefTag(refTag), cookie.getValue());
}
Also used : CookieStore(java.net.CookieStore) Project(com.kickstarter.models.Project) RefTag(com.kickstarter.libs.RefTag) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager) Test(org.junit.Test)

Example 100 with HttpCookie

use of java.net.HttpCookie in project android-oss by kickstarter.

the class RefTagUtilsTest method testBuildCookieForRefTagAndProject_WithWellFormedUrl.

@Test
public void testBuildCookieForRefTagAndProject_WithWellFormedUrl() {
    final Project project = ProjectFactory.project();
    final RefTag refTag = RefTag.category();
    final HttpCookie cookie = RefTagUtils.buildCookieWithRefTagAndProject(refTag, project);
    assertNotNull(cookie);
    assertEquals(ProjectUtils.timeInSecondsUntilDeadline(project).longValue(), cookie.getMaxAge());
    assertEquals("www.kickstarter.com", cookie.getDomain());
}
Also used : Project(com.kickstarter.models.Project) RefTag(com.kickstarter.libs.RefTag) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Aggregations

HttpCookie (java.net.HttpCookie)148 CookieManager (java.net.CookieManager)49 CookieStore (java.net.CookieStore)33 URI (java.net.URI)31 Test (org.junit.Test)31 IOException (java.io.IOException)14 Test (org.testng.annotations.Test)13 MockResponse (com.google.mockwebserver.MockResponse)11 MockWebServer (com.google.mockwebserver.MockWebServer)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Project (com.kickstarter.models.Project)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 URL (java.net.URL)5 Cookie (javax.servlet.http.Cookie)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 MockWebServer (okhttp3.mockwebserver.MockWebServer)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5