Package java.net

Examples of java.net.CookieManager

The implementation conforms to RFC 2965, section 3.3. @version %I%, %E% @author Edward Wang @since 1.6


    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        cookieManager = new CookieManager();
        cookieStore = cookieManager.getCookieStore();
    }
View Full Code Here


public class CookieManagerTest extends TestCase {

    private static void checkValidParams4Get(URI uri,
            Map<String, List<String>> map) throws IOException {
        CookieManager manager = new CookieManager();
        try {
            manager.get(uri, map);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
View Full Code Here

    }

    private static void checkValidParams4Put(URI uri,
            Map<String, List<String>> map) throws IOException {
        CookieManager manager = new CookieManager();
        try {
            manager.put(uri, map);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
View Full Code Here

    }

    private static CookieManager store(String[][] cookies,
            Map<String, List<String>> responseHeaders, CookiePolicy policy)
            throws IOException, URISyntaxException {
        CookieManager manager = new CookieManager(null, policy);
        // Put all cookies into manager
        for (int i = 0; i < cookies.length; i++) {
            for (int j = 2; j < cookies[i].length; j += 2) {
                URI uri = new URI(cookies[i][j]);
                manager.put(uri, responseHeaders);
            }
        }
        return manager;
    }
View Full Code Here

        // requires path of cookie is the prefix of uri
        // domain of cookie must match that of uri
        Map<String, List<String>> responseHeaders = addCookie(new String[][] {
                cookies[0], cookies[1] });
        CookieManager manager = store(
                new String[][] { cookies[0], cookies[1] }, responseHeaders,
                null);

        HashMap<String, List<String>> dummyMap = new HashMap<String, List<String>>();
        Map<String, List<String>> map = manager.get(new URI("http://a.b.c/"),
                dummyMap);

        assertEquals(1, map.size());
        List<String> list = map.get("Cookie");
        assertEquals(1, list.size());

        // requires path of cookie is the prefix of uri
        map = manager.get(new URI("http://a.b.c/te"), dummyMap);
        list = map.get("Cookie");
        assertEquals(2, list.size());

        // If all cookies are of version 1, then $version=1 will be added
        // ,no matter the value cookie-key
        responseHeaders = addCookie(new String[][] { cookies[2] });
        manager = store(new String[][] { cookies[2] }, responseHeaders, null);
        map = manager.get(new URI("http://a.beg.com/test"), dummyMap);
        list = map.get("Cookie");
        assertEquals("$Version=\"1\"", list.get(0));
        assertEquals(3, list.size());

        // cookie-key will not have effect on determining cookie version
        responseHeaders = addCookie(new String[][] { cookies[3] });
        manager = store(new String[][] { cookies[3] }, responseHeaders, null);
        map = manager.get(new URI("http://a.test.org/"), responseHeaders);
        list = map.get("Cookie");
        assertEquals(1, list.size());
        assertEquals("Set-cookie3:NAME=VALUE", list.get(0));

        // When key is null, no cookie can be stored/retrieved, even if policy =
        // ACCEPT_ALL
        responseHeaders = addCookie(new String[][] { cookies[4] });
        manager = store(new String[][] { cookies[4] }, responseHeaders,
                CookiePolicy.ACCEPT_ALL);
        map = manager.get(new URI("http://a.test.org/"), responseHeaders);
        list = map.get("Cookie");
        assertEquals(0, list.size());

        // All cookies will be rejected if policy == ACCEPT_NONE
        responseHeaders = addCookie(new String[][] { cookies[3] });
        manager = store(new String[][] { cookies[3] }, responseHeaders,
                CookiePolicy.ACCEPT_NONE);
        map = manager.get(new URI("http://a.test.org/"), responseHeaders);
        list = map.get("Cookie");
        assertEquals(0, list.size());
       
        responseHeaders = addCookie(new String[][] { cookies[5] });
        manager = store(new String[][] { cookies[5] }, responseHeaders,
View Full Code Here

        if (uriMatcher.matches())
        {
            String afterPath = uriMatcher.group(9);
            _appendMessageType = afterPath == null || afterPath.trim().length() == 0;
        }
        _cookieManager = new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
    }
View Full Code Here

        super.doStart();
    }

    private CookieManager newCookieManager()
    {
        return new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
    }
View Full Code Here

        super.doStart();
    }

    private CookieManager newCookieManager()
    {
        return new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
    }
View Full Code Here

        super.doStart();
    }

    private CookieManager newCookieManager()
    {
        return new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
    }
View Full Code Here

    protected void storeCookies(Map<String, List<String>> headers)
    {
        try
        {
            CookieManager cookieManager = new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
            cookieManager.put(URI.create(getURL()), headers);
        }
        catch (IOException x)
        {
            if (logger.isDebugEnabled())
                logger.debug("Could not parse cookies", x);
View Full Code Here

TOP

Related Classes of java.net.CookieManager

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.