Package our.apache.commons.httpclient.cookie

Examples of our.apache.commons.httpclient.cookie.RFC2109Spec


   
    /** Test of addCookies method, of class com.volantis.mcs.servlet.CookieStore. */
    public void testAddCookies() throws MalformedCookieException {
        CookieStore store = new CookieStore();
       
        RFC2109Spec spec = new RFC2109Spec();
        Cookie[] c = spec.parse( "www.roadrunner.com", 80, "/acme/login",
                    false,
                    "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; " +
                    "Path=\"/acme\"" );
        store.addCookies(c);
        assertEquals( 1, store.getCookies(
View Full Code Here


    public void testGetCookies() throws MalformedCookieException {
           
        Cookie[] cookies;
        Cookie[] sentCookies;
       
        RFC2109Spec spec = new RFC2109Spec();
       
        CookieStore store = new CookieStore();
        // POST /acme/login HTTP/1.1 - User identifies self via a form
        cookies = spec.parse( "www.roadrunner.com", 80, "/acme/login", false,
                    "Customer=\"WILE_E_COYOTE\"; Version=\"1\"; " +
                    "Path=\"/acme\"" );
        store.addCookies( cookies );

        // User chooses an item. Should send the Customer cookie
        // POST /acme/pickitem HTTP/1.1 - User selects item
        sentCookies = store.getCookies( "www.roadrunner.com", 80,
                                     "/acme/pickitem" );
        assertEquals( 1, sentCookies.length );
        assertEquals( "Customer", sentCookies[0].getName() );
        assertEquals( "WILE_E_COYOTE", sentCookies[0].getValue() );
        assertEquals( "/acme", sentCookies[0].getPath() );
       
        cookies = spec.parse( "www.roadrunner.com", 80, "/acme/pickitem", false,
                "Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\"; " +
                "Path=\"/acme\"" );
        store.addCookies( cookies );
       
        // User selects ammo for the chosen item
        // POST /acme/pickitem/parts HTTP/1.1 - User selects parts
        sentCookies = store.getCookies( "www.roadrunner.com", 80,
                                     "/acme/pickitem/ammo" );
        assertEquals( 2, sentCookies.length );
        assertEquals( "Customer", sentCookies[0].getName() );
        assertEquals( "WILE_E_COYOTE", sentCookies[0].getValue() );
        assertEquals( "/acme", sentCookies[0].getPath() );
        assertEquals( "Part_Number", sentCookies[1].getName() );
        assertEquals( "Rocket_Launcher_0001", sentCookies[1].getValue() );
        assertEquals( "/acme", sentCookies[1].getPath() );

        cookies = spec.parse( "www.roadrunner.com", 80, "/acme/pickitem/ammo",
                false, "Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; " +
                "Path=\"/acme/pickitem\"" );
        store.addCookies( cookies );

        // This is a test for the path on the ammo cookie. Because it is
        // longer, it should be sent ahead of the customer and launcher
        // cookies. It will not be sent in the next request when we go
        // back 'above' the ammo path.
        sentCookies = store.getCookies( "www.roadrunner.com", 80,
                                     "/acme/pickitem/ammo" );
        assertEquals( 3, sentCookies.length );
        assertEquals( "Part_Number", sentCookies[0].getName() );
        assertEquals( "Riding_Rocket_0023", sentCookies[0].getValue() );
        assertEquals( "/acme/pickitem", sentCookies[0].getPath() );
        assertEquals( "Customer", sentCookies[1].getName() );
        assertEquals( "WILE_E_COYOTE", sentCookies[1].getValue() );
        assertEquals( "/acme", sentCookies[1].getPath() );
        assertEquals( "Part_Number", sentCookies[2].getName() );
        assertEquals( "Rocket_Launcher_0001", sentCookies[2].getValue() );
        assertEquals( "/acme", sentCookies[2].getPath() );
       
       
        // User selects shipping method from a form. Should send both the
        // Customer and part number cookies.
        // POST /acme/shipping HTTP/1.1 - User selects shipping method
        sentCookies = store.getCookies( "www.roadrunner.com", 80,
                                     "/acme/shipping" );
        assertEquals( 2, sentCookies.length );
        assertEquals( "Customer", sentCookies[0].getName() );
        assertEquals( "WILE_E_COYOTE", sentCookies[0].getValue() );
        assertEquals( "/acme", sentCookies[0].getPath() );
        assertEquals( "Part_Number", sentCookies[1].getName() );
        assertEquals( "Rocket_Launcher_0001", sentCookies[1].getValue() );
        assertEquals( "/acme", sentCookies[1].getPath() );
       
        cookies = spec.parse( "www.roadrunner.com", 80, "/acme/shipping", false,
                "Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"" );
        store.addCookies(cookies);
       
        // User chooses to process the order. Should send the Customer, part
        // number and shpping cookies.
View Full Code Here

       
        if( port == -1 ){
            port = 80;
        }

        RFC2109Spec spec = new RFC2109Spec();
        return spec.match( host, port, path, false, cookiejar );       
    }
View Full Code Here

TOP

Related Classes of our.apache.commons.httpclient.cookie.RFC2109Spec

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.