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

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


                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        HttpContent content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        Map expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        expectedHeaders.put("foo", "bar");
        boolean ageFound = false;
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("age".equals(name) && !ageFound) {
                // age must be at least 0
                assertTrue(Integer.parseInt(header.getValue()) >= 0);
                ageFound = true;
            } else {
                final String value =
                    (String) expectedHeaders.remove(name);
                assertEquals(value, header.getValue());
            }
        }
        assertTrue(ageFound);
        assertTrue(expectedHeaders.isEmpty());

        // 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,
                "Foo: baz",
                ""});

        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());
        // original headers are kept, Date and Foo headers are updated
        expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        expectedHeaders.put("foo", "baz");
        ageFound = false;
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("age".equals(name) && !ageFound) {
                // age must be at least 0
                assertTrue(Integer.parseInt(header.getValue()) >= 0);
View Full Code Here


                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        HttpContent content = (HttpContent) manager.getURLContent(url, null, null);
        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());
View Full Code Here

                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        final HttpContent content =
            (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            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
View Full Code Here

TOP

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

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.