Package org.apache.http.cookie

Examples of org.apache.http.cookie.ClientCookie


        CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
        Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1;");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertEquals("name", cookie.getName());
        assertEquals("value", cookie.getValue());
    }
View Full Code Here


        CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
        Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1;");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertEquals(1, cookie.getVersion());
        assertTrue(cookie.containsAttribute(ClientCookie.VERSION_ATTR));
    }
View Full Code Here

        Header header = new BasicHeader("Set-Cookie2", "name=value;Max-age=3600;Version=1;Max-age=nonsense");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        // only the first occurence of max-age attribute is considered, others ignored
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertFalse(cookie.isExpired(new Date()));
    }
View Full Code Here

        // Max-age is OPTIONAL, defaults to session cookie
        Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertFalse(cookie.isPersistent());
    }
View Full Code Here

        CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
        Header header = new BasicHeader("Set-Cookie2", "name=value;Secure;Version=1");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertTrue(cookie.isSecure());
    }
View Full Code Here

        CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
        Header header = new BasicHeader("Set-Cookie2", "name=value;Discard;Max-age=36000;Version=1");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        // discard overrides max-age
        assertFalse(cookie.isPersistent());

        // Discard is OPTIONAL, default behavior is dictated by max-age
        header = new BasicHeader("Set-Cookie2", "name=value;Max-age=36000;Version=1");
        cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        cookie = (ClientCookie) cookies.get(0);
        assertTrue(cookie.isPersistent());
    }
View Full Code Here

        Header header = new BasicHeader("Set-Cookie2", "name=value;Comment=\"good cookie\";" +
                "CommentURL=\"www.domain.com/goodcookie/\";Secure;Version=1");
        List<Cookie> cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertEquals("good cookie", cookie.getComment());
        assertEquals("www.domain.com/goodcookie/", cookie.getCommentURL());
        assertTrue(cookie.isSecure());

        // Comment, CommentURL, Secure are OPTIONAL
        header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
        cookies = cookiespec.parse(header, origin);
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        cookie = (ClientCookie) cookies.get(0);
        assertFalse(cookie.isSecure());
    }
View Full Code Here

        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        // cookie domain must string match request host
        assertEquals("www.domain.com", cookie.getDomain());
    }
View Full Code Here

        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertEquals(".domain.com", cookie.getDomain());
    }
View Full Code Here

        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        ClientCookie cookie = (ClientCookie) cookies.get(0);
        assertEquals(".local", cookie.getDomain());

        // when domain is NOT specified as .local, simple host names are invalid
        header = new BasicHeader("Set-Cookie2", "name=value; domain=domain.com; version=1");
        try {
            // since domain is not .local, this must fail
View Full Code Here

TOP

Related Classes of org.apache.http.cookie.ClientCookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.