Package org.apache.http.cookie

Examples of org.apache.http.cookie.CookieSpec


     */
    public void testDomainCaseInsensitivity() throws Exception {
        Header header = new BasicHeader("Set-Cookie",
            "name=value; path=/; domain=.whatever.com");

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.WhatEver.com", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        assertEquals(".whatever.com", cookies.get(0).getDomain());
    }
View Full Code Here


        String headerValue = "custno = 12345; comment=test; version=1," +
            " name=John; version=1; max-age=600; secure; domain=.apache.org";

        Header header = new BasicHeader("set-cookie", headerValue);

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertEquals(2, cookies.size());

        assertEquals("custno", cookies.get(0).getName());
        assertEquals("12345", cookies.get(0).getValue());
View Full Code Here

        String headerValue = "custno=12345;comment=test; version=1," +
            "name=John;version=1;max-age=600;secure;domain=.apache.org";

        Header header = new BasicHeader("set-cookie", headerValue);

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }

        assertEquals(2, cookies.size());

        assertEquals("custno", cookies.get(0).getName());
View Full Code Here

    public void testParse3() throws Exception {
        String headerValue =
            "name=\"Doe, John\";version=1;max-age=600;secure;domain=.apache.org";
        Header header = new BasicHeader("set-cookie", headerValue);

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }

        assertEquals(1, cookies.size());

        assertEquals("name", cookies.get(0).getName());
View Full Code Here

    public void testQuotedExpiresAttribute() throws Exception {
        String headerValue = "custno=12345;Expires='Thu, 01-Jan-2070 00:00:10 GMT'";

        Header header = new BasicHeader("set-cookie", headerValue);

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertNotNull("Expected some cookies",cookies);
        assertEquals("Expected 1 cookie",1,cookies.size());
        assertNotNull("Expected cookie to have getExpiryDate",cookies.get(0).getExpiryDate());
    }
View Full Code Here

    public void testSecurityError() throws Exception {
        String headerValue = "custno=12345;comment=test; version=1," +
            "name=John;version=1;max-age=600;secure;domain=jakarta.apache.org";
        Header header = new BasicHeader("set-cookie", headerValue);

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
        try {
            List<Cookie> cookies = cookiespec.parse(header, origin);
            for (int i = 0; i < cookies.size(); i++) {
                cookiespec.validate(cookies.get(i), origin);
            }
            fail("MalformedCookieException exception should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
        }
View Full Code Here

    }

    public void testParseSimple() throws Exception {
        Header header = new BasicHeader("Set-Cookie","cookie-name=cookie-value");
       
        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path/path", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertEquals("Found 1 cookie.",1,cookies.size());
        assertEquals("Name","cookie-name",cookies.get(0).getName());
        assertEquals("Value","cookie-value",cookies.get(0).getValue());
        assertTrue("Comment",null == cookies.get(0).getComment());
View Full Code Here

    }
    public void testParseSimple2() throws Exception {
        Header header = new BasicHeader("Set-Cookie", "cookie-name=cookie-value");
   
        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertEquals("Found 1 cookie.", 1, cookies.size());
        assertEquals("Name", "cookie-name", cookies.get(0).getName());
        assertEquals("Value", "cookie-value", cookies.get(0).getValue());
        assertTrue("Comment", null == cookies.get(0).getComment());
View Full Code Here

    }
    public void testParseNoName() throws Exception {
        Header header = new BasicHeader("Set-Cookie","=stuff; path=/");

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
        try {
            List<Cookie> cookies = cookiespec.parse(header, origin);
            for (int i = 0; i < cookies.size(); i++) {
                cookiespec.validate(cookies.get(i), origin);
            }
            fail("MalformedCookieException should have been thrown");
        } catch (MalformedCookieException ex) {
            // expected
        }
View Full Code Here

    }
    public void testParseNoValue() throws Exception {
        Header header = new BasicHeader("Set-Cookie","cookie-name=");

        CookieSpec cookiespec = new BrowserCompatSpec();
        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
        List<Cookie> cookies = cookiespec.parse(header, origin);
        for (int i = 0; i < cookies.size(); i++) {
            cookiespec.validate(cookies.get(i), origin);
        }
        assertEquals("Found 1 cookie.",1,cookies.size());
        assertEquals("Name","cookie-name",cookies.get(0).getName());
        assertEquals("Value", "", cookies.get(0).getValue());
        assertTrue("Comment",null == cookies.get(0).getComment());
View Full Code Here

TOP

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

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.