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

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


    // javadoc inherited
    public HTTPMessageEntities getHeaders() throws HTTPException {
        if (headers == null) {
            headers = FACTORY.createHTTPMessageEntities();
            for (Iterator iter = httpContent.getHeaders(); iter.hasNext(); ) {
                final Header header = (Header) iter.next();
                final List values;
                try {
                    values = HttpClientUtils.getHeaderValueList(
                        new org.apache.commons.httpclient.Header(
                            header.getName(), header.getValue()));
                } catch (HttpException e) {
                    throw new HTTPException(e);
                }
                for (Iterator valuesIter = values.iterator();
                     valuesIter.hasNext(); ) {
                    final com.volantis.shared.net.http.headers.Header entity =
                        FACTORY.createHeader(header.getName());
                    final String value = (String) valuesIter.next();
                    entity.setValue(value);
                    headers.add(entity);
                }
            }
View Full Code Here


                    final Cookie cookie = new CookieImpl(httpCookie, baseTime);
                    cookies.add(cookie);
                }
            } else {
                final String headerValue = httpHeader.getValue();
                final Header header = new HeaderImpl(headerName, headerValue);
                headers.add(header);
            }
        }
    }
View Full Code Here

        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        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());
    }
View Full Code Here

        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        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());

        // hop-by-hop headers should not be removed if the content is not
        // cacheable
        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.1 200 OK",
                "Date: " + currentDate,
                "Content-Type: text/plain",
                "Cache-Control: private",
                "Connection: connection-value",
                "Keep-Alive: keep-alive-value",
                "Proxy-Authenticate: proxy-authenticate-value",
                "Proxy-Authorization: proxy-authorization-value",
                "TE: te-value",
                "Trailers: trailers-value",
                "Transfer-Encoding: transfer-encoding-value",
                "Upgrade: upgrade-value",
                "",
                "<p>hello</p>"});

        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());
        expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "private");
        expectedHeaders.put("connection", "connection-value");
        expectedHeaders.put("keep-alive", "keep-alive-value");
        expectedHeaders.put("proxy-authenticate", "proxy-authenticate-value");
        expectedHeaders.put("proxy-authorization", "proxy-authorization-value");
        expectedHeaders.put("te", "te-value");
        expectedHeaders.put("trailers", "trailers-value");
        expectedHeaders.put("transfer-encoding", "transfer-encoding-value");
        expectedHeaders.put("upgrade", "upgrade-value");
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            final String value =
                (String) expectedHeaders.remove(name);
            assertEquals(value, header.getValue());
        }
        assertTrue(expectedHeaders.isEmpty());
        assertFalse(serverMock.hasTransactions());
    }
View Full Code Here

        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        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());

        // content is no longer cacheable so hop-by-hop headers should be
        // returned with the HTTP content
        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-Type: text/plain",
                "Cache-Control: private",
                "Connection: connection-value",
                "Keep-Alive: keep-alive-value",
                "Proxy-Authenticate: proxy-authenticate-value",
                "Proxy-Authorization: proxy-authorization-value",
                "TE: te-value",
                "Trailers: trailers-value",
                "Transfer-Encoding: transfer-encoding-value",
                "Upgrade: upgrade-value",
                ""});

        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());
        expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "private");
        expectedHeaders.put("etag", "\"aa\"");
        expectedHeaders.put("connection", "connection-value");
        expectedHeaders.put("keep-alive", "keep-alive-value");
        expectedHeaders.put("proxy-authenticate", "proxy-authenticate-value");
        expectedHeaders.put("proxy-authorization", "proxy-authorization-value");
        expectedHeaders.put("te", "te-value");
        expectedHeaders.put("trailers", "trailers-value");
        expectedHeaders.put("transfer-encoding", "transfer-encoding-value");
        expectedHeaders.put("upgrade", "upgrade-value");
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            final String value =
                (String) expectedHeaders.remove(name);
            assertEquals(value, header.getValue());
        }
        assertTrue(expectedHeaders.isEmpty());
        assertFalse(serverMock.hasTransactions());
    }
View Full Code Here

        // first response should contain both Warings
        Set expectedWarningHeaders = new HashSet();
        expectedWarningHeaders.add("113 Heuristic expiration");
        expectedWarningHeaders.add("214 Transformation applied");
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("warning".equals(name)) {
                assertTrue(expectedWarningHeaders.remove(header.getValue()));
            }
        }
        assertTrue(expectedWarningHeaders.isEmpty());

        // second request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        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: Fri, 31 Dec 1999 23:59:59 GMT",
                ""});

        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());
        // 1xx Warning should be removed automatically
        expectedWarningHeaders = new HashSet();
        expectedWarningHeaders.add("214 Transformation applied");
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("warning".equals(name)) {
                assertTrue(expectedWarningHeaders.remove(header.getValue()));
            }
        }
        assertTrue(expectedWarningHeaders.isEmpty());

        // third request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        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: Fri, 31 Dec 1999 23:59:59 GMT",
                "Warning: 299 Miscellaneous persistent warning",
                ""});

        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());
        // new 2xx Warning is added to the list of warnings, the original 2xx is
        // still kept
        expectedWarningHeaders = new HashSet();
        expectedWarningHeaders.add("214 Transformation applied");
        expectedWarningHeaders.add("299 Miscellaneous persistent warning");
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("warning".equals(name)) {
                assertTrue(expectedWarningHeaders.remove(header.getValue()));
            }
        }
        assertTrue(expectedWarningHeaders.isEmpty());
        assertFalse(serverMock.hasTransactions());
    }
View Full Code Here

        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);
                ageFound = true;
            } else {
                final String value =
                    (String) expectedHeaders.remove(name);
                assertEquals(value, header.getValue());
            }
        }
        assertTrue(ageFound);
        assertTrue(expectedHeaders.isEmpty());
        assertFalse(serverMock.hasTransactions());
View Full Code Here

    private int getAgeHeaderValue(final Iterator headersIter) {
        int age = -1;
        // go through all of the headers to see if there are more than one Age
        // header
        while (headersIter.hasNext()) {
            final Header header = (Header) headersIter.next();
            if ("age".equalsIgnoreCase(header.getName())) {
                assertTrue(age == -1);
                age = Integer.parseInt(header.getValue());
                assertTrue(age != -1);
            }
        }
        assertTrue(age != -1);
        return age;
View Full Code Here

TOP

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

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.