Search in sources :

Example 6 with DirectBufferCache

use of io.undertow.server.handlers.cache.DirectBufferCache in project undertow by undertow-io.

the class RangeRequestTestCase method setup.

@BeforeClass
public static void setup() throws URISyntaxException {
    Path rootPath = Paths.get(RangeRequestTestCase.class.getResource("range.txt").toURI()).getParent();
    PathHandler path = Handlers.path();
    path.addPrefixPath("/path", new ByteRangeHandler(new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            exchange.getResponseHeaders().put(Headers.LAST_MODIFIED, DateUtils.toDateString(new Date(10000)));
            exchange.getResponseHeaders().put(Headers.ETAG, "\"someetag\"");
            exchange.getResponseSender().send("0123456789");
        }
    }, true));
    path.addPrefixPath("/resource", new ResourceHandler(new PathResourceManager(rootPath, 10485760)).setDirectoryListingEnabled(true));
    path.addPrefixPath("/cachedresource", new ResourceHandler(new CachingResourceManager(1000, 1000000, new DirectBufferCache(1000, 10, 10000), new PathResourceManager(rootPath, 10485760), -1)).setDirectoryListingEnabled(true));
    DefaultServer.setRootHandler(path);
}
Also used : Path(java.nio.file.Path) HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) DirectBufferCache(io.undertow.server.handlers.cache.DirectBufferCache) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) Date(java.util.Date) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) BeforeClass(org.junit.BeforeClass)

Aggregations

DirectBufferCache (io.undertow.server.handlers.cache.DirectBufferCache)6 HttpHandler (io.undertow.server.HttpHandler)2 HttpServerExchange (io.undertow.server.HttpServerExchange)2 CacheHandler (io.undertow.server.handlers.cache.CacheHandler)2 PathResourceManager (io.undertow.server.handlers.resource.PathResourceManager)2 ResourceHandler (io.undertow.server.handlers.resource.ResourceHandler)2 TestHttpClient (io.undertow.testutils.TestHttpClient)2 ByteBuffer (java.nio.ByteBuffer)2 Path (java.nio.file.Path)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 Test (org.junit.Test)2 Sender (io.undertow.io.Sender)1 CanonicalPathHandler (io.undertow.server.handlers.CanonicalPathHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 ResponseCache (io.undertow.server.handlers.cache.ResponseCache)1 ResponseCachingSender (io.undertow.server.handlers.cache.ResponseCachingSender)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1