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

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


            transferMetaData(executor);
            // if this is a GET then try the cache
            if (requestType.equals(HTTPRequestType.GET) &&
                canRequestBeSatisfiedByCache(requestHeaders)) {
                // try to read it from the dependency context first
                HttpContent content = null;
                if (xmlPipelineContext != null) {
                    final DependencyContext dependencyContext =
                        xmlPipelineContext.getDependencyContext();
                    if (dependencyContext != null) {
                        content = (HttpContent)
                            dependencyContext.removeProperty(keyUrl);
                    }
                }
                if (content == null) {
                    try {
                        // This path requests the page through the cache.
                        content = (HttpContent) cache.retrieve(keyUrl,
                            new HttpCacheableObjectProvider(
                                executor, cache.getRootGroup(), cache));
                    } catch (RuntimeHttpException e) {
                        throw (HTTPException) e.getCause();
                    }
                }
                respAccessor = new HttpContentWrapper(content);
                dependency = content.getDependency();
            } else {
                // This path is for the types of request whose response should
                // not be cached. POST and currently anything that is not
                // a GET. We delegate directly to the target
                // AbstractPluggableHTTPManager to get the data.
View Full Code Here


     */
    public ProviderResult retrieve(final SystemClock clock,
                                   final Object key,
                                   final CacheEntry entry) {

        HttpContent httpContent;
        CachedHttpContentState state = null;
        HTTPResponseAccessor accessor;
        boolean cacheable = false;
        ProviderResult result = null;
        try {
View Full Code Here

    // javadoc inherited
    public HttpContent retrieve(final URL url, final Period timeout,
                                final HttpUrlConfiguration httpConfig)
            throws IOException {
        HttpContent httpContent = null;
        // check the dependency context first as the dependency might stored
        // the content there on a revalidate
        if (httpConfig != null) {
            final DependencyContext dependencyContext =
                httpConfig.getDependencyContext();
View Full Code Here

            // record response time
            builder.setResponseTime(clock.getCurrentTime());

            // get the content either from the response or from the cache
            final HttpContent content;
            final int statusCode = method.getStatusCode();
            if (statusCode == HttpStatus.SC_OK) {
                cacheState = builder.build();
                final HttpContent returnedContent =
                    new HttpClientHttpContent(method);
                if (!cacheState.isCacheable()) {
                    content = returnedContent;
                } else {
                    content = new CachedHttpContent(
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.0", content.getHttpVersion());
        assertEquals(200, content.getStatusCode());
        final Map expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        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);
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("HTTP/1.1", content.getHttpVersion());
        assertEquals(200, content.getStatusCode());
        // no hop-by-hop header should be among the headers stored in the HTTP
        // content
        Map expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        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());
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("HTTP/1.1", content.getHttpVersion());
        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\"");
        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());
View Full Code Here

        // create a manager using the system clock mock
        final URLContentManager manager = createURLContentManager(
            clock, Period.INDEFINITELY, true, 1000);
        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()));
        // time shift is 10 seconds so Age must be at least 10
        assertTrue(getAgeHeaderValue(content.getHeaders()) >= 10);
        assertEquals(200, content.getStatusCode());

        timeShift[0] = 100000; // 100 seconds
        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Cached content is returned", "<p>hello</p>\n",
            toString(content.getInputStream()));
        // time shift is 100 seconds
        assertTrue(getAgeHeaderValue(content.getHeaders()) >= 100);
        assertEquals(200, content.getStatusCode());
        assertEquals("HTTP/1.0", content.getHttpVersion());
        assertFalse(serverMock.hasTransactions());
    }
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());
        assertEquals("HTTP/1.0", content.getHttpVersion());

        // 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.1 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());
        assertEquals("HTTP/1.0", content.getHttpVersion());
        assertFalse(serverMock.hasTransactions());
    }
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());
        // 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()));
            }
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.