Package com.volantis.shared.net.url.http

Examples of com.volantis.shared.net.url.http.Cookie


    // javadoc inherited
    public HTTPMessageEntities getCookies() throws HTTPException {
        if (cookies == null) {
            cookies = FACTORY.createHTTPMessageEntities();
            for (Iterator iter = httpContent.getCookies(); iter.hasNext(); ) {
                final Cookie cookie = (Cookie) iter.next();
                final com.volantis.shared.net.http.cookies.Cookie cookieEntity =
                    FACTORY.createCookie(
                        cookie.getName(), cookie.getDomain(), cookie.getPath());
                cookieEntity.setComment(cookie.getComment());
                cookieEntity.setMaxAge(cookie.getMaxAge());
                cookieEntity.setSecure(cookie.isSecure());
                cookieEntity.setValue(cookie.getValue());
                cookieEntity.setVersion(
                    CookieVersion.getCookieVersion(cookie.getVersion()));
                cookies.add(cookieEntity);
            }
        }
        return cookies;
    }
View Full Code Here


                    HttpClientUtils.createCookieArray(method, httpHeader);
                final long baseTime = System.currentTimeMillis();
                for (int j = 0; j < httpCookies.length; j++) {
                    final org.apache.commons.httpclient.Cookie httpCookie =
                        httpCookies[j];
                    final Cookie cookie = new CookieImpl(httpCookie, baseTime);
                    cookies.add(cookie);
                }
            } else {
                final String headerValue = httpHeader.getValue();
                final Header header = new HeaderImpl(headerName, headerValue);
View Full Code Here

        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        Iterator cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        final Cookie fooCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("foo", fooCookie.getName());
        assertEquals("bar", fooCookie.getValue());

        // second request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        currentDate = RFC1123.format(new Date());
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 304 Not Modified",
                "Date: " + currentDate,
                "Set-Cookie: hello=world",
                ""});

        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was not modified, cached entry is returned",
            "<p>hello</p>\n", toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        Cookie helloCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("hello", helloCookie.getName());
        assertEquals("world", helloCookie.getValue());


        // third request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        currentDate = RFC1123.format(new Date());
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 304 Not Modified",
                "Date: " + currentDate,
                ""});

        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was not modified, cached entry is returned",
            "<p>hello</p>\n", toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        helloCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("hello", helloCookie.getName());
        assertEquals("world", helloCookie.getValue());
        assertFalse(serverMock.hasTransactions());
    }
View Full Code Here

            toString(content.getInputStream()));
        assertEquals("HTTP/1.1", content.getHttpVersion());
        assertEquals(200, content.getStatusCode());
        final Map cookies = new HashMap();
        for (Iterator iter = content.getCookies(); iter.hasNext(); ) {
            final Cookie cookie = (Cookie) iter.next();
            cookies.put(cookie.getName(), cookie);
        }

        // we should have 3 cookies
        assertEquals(3, cookies.size());

        final Cookie helloCookie = (Cookie) cookies.get("hello");
        assertEquals("world", helloCookie.getValue());
        assertEquals("www.example.com", helloCookie.getDomain());
        assertEquals("hello world", helloCookie.getComment());
        assertTrue(helloCookie.getMaxAge() > 95);
        assertEquals(0, helloCookie.getVersion());
        assertFalse(helloCookie.isSecure());

        final Cookie fooCookie = (Cookie) cookies.get("foo");
        assertEquals("bar", fooCookie.getValue());
        assertEquals("localhost", fooCookie.getDomain());
        assertNull(fooCookie.getComment());
        assertEquals(-1, fooCookie.getMaxAge());
        assertEquals(0, fooCookie.getVersion());
        assertTrue(fooCookie.isSecure());

        final Cookie nameOnlyCookie = (Cookie) cookies.get("name-only");
        assertNull(nameOnlyCookie.getValue());
        assertEquals("localhost", nameOnlyCookie.getDomain());
        assertNull(nameOnlyCookie.getComment());
        assertEquals(-1, nameOnlyCookie.getMaxAge());
        assertEquals(0, nameOnlyCookie.getVersion());
        assertFalse(nameOnlyCookie.isSecure());
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.url.http.Cookie

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.