Package ign.middleman.helpers

Examples of ign.middleman.helpers.WebResponse


        this.cachedRulesKey = cachedRulesKey;
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        WebResponse r = getWebResponse(request, url(request));
        if (r != null) {
            r.writeTo(response);
        }
    }
View Full Code Here


            }
        } else {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("cache miss: " + url);
            }
            final WebResponse r = getWebResponse(request, url);
            if (r != null) {
                try {
                    r.writeTo(response);
                } finally {
                    if (r.isOK()) {
                        final Map<String, List<String>> headers = convertRequestHeaders(request);
                        executor.execute(new Runnable() {
                            public void run() {
                                cacheAside(method, headers, url, cacheKey, r);
                            }
View Full Code Here

                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Refreshing " + url);
                }

                WebResponse r = getWebResponse(url, method, headers);
                if (r != null && r.isOK()) {
                    cacheWebResponse(cacheKey, r);
                } else if (r != null && r.is4XX()) {
                    flushWebResponse(cacheKey);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
View Full Code Here

            Collection<Rule> rules = fetchRulesInLastTwoHours();
            if (rules != null) {
                for (Rule rule : rules) {
                    try {
                        if (rule.matches(url, timestamp)) {
                            WebResponse r = getWebResponse(url, method, headers);
                            if (r != null && r.isOK()) {
                                cacheWebResponse(cacheKey, r);
                                return;
                            }
                        }
                    } catch (IOException e) {
View Full Code Here

    @Test
    public void proxyTest() throws IOException {
        WebClient wc = new WebClient();
        Proxy via = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port));
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/ok", via, null);
        assertEquals(200, wr.getStatus());
    }
View Full Code Here

    }

    @Test
    public void okTest() throws IOException {
        WebClient wc = new WebClient();
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/ok", null, null);
        assertEquals(200, wr.getStatus());
        assertEquals("GET", wr.getMethod());
        assertEquals("OK", wr.getMessage());
        assertEquals("text/plain; charset=utf-8", wr.getHeaders().get("Content-Type").get(0));
        assertEquals("Hello World", new String(wr.getBody()));

    }
View Full Code Here

    }

    @Test
    public void okTestWithListener() throws IOException {
        WebClient wc = new WebClient();
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/ok", null, new SimpleWebClientListener());
        assertEquals(200, wr.getStatus());
        assertEquals("OK", wr.getMessage());
        assertEquals("text/plain; charset=utf-8", wr.getHeaders().get("Content-Type").get(0));
        assertEquals("Hello World", new String(wr.getBody()));

    }
View Full Code Here

    }

    @Test
    public void notModifiedTest() throws IOException {
        WebClient wc = new WebClient();
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/not-modified", null, null);
        assertEquals(304, wr.getStatus());

    }
View Full Code Here

    }

    @Test
    public void notModifiedTestWithListener() throws IOException {
        WebClient wc = new WebClient();
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/not-modified", null, new SimpleWebClientListener());
        assertEquals(304, wr.getStatus());

    }
View Full Code Here

    }

    @Test
    public void notFoundTest() throws IOException {
        WebClient wc = new WebClient();
        WebResponse wr = wc.raw("GET", "http://localhost:" + port + "/not-found", null, null);
        assertEquals(404, wr.getStatus());
        assertEquals("Not Found", wr.getMessage());
        assertEquals("text/html; charset=utf-8", wr.getHeaders().get("Content-Type").get(0));
        assertEquals("Hello World", new String(wr.getBody()));

    }
View Full Code Here

TOP

Related Classes of ign.middleman.helpers.WebResponse

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.