Search in sources :

Example 1 with StaticRoute

use of org.webpieces.router.impl.StaticRoute in project webpieces by deanhiller.

the class R1RouterBuilder method addStaticRoute.

private void addStaticRoute(String urlPath, String fileSystemPath, boolean isOnClassPath) {
    if (isOnClassPath)
        throw new UnsupportedOperationException("oops, isOnClassPath not supported yet");
    StaticRoute route = new StaticRoute(new UrlPath(routerInfo, urlPath), fileSystemPath, isOnClassPath, holder.getCachedCompressedDirectory());
    staticRoutes.add(route);
    log.info("scope:'" + routerInfo + "' adding static route=" + route.getFullPath() + " fileSystemPath=" + route.getFileSystemPath());
    RouteMeta meta = new RouteMeta(route, holder.getInjector(), currentPackage.get(), holder.getUrlEncoding());
    allRouting.addStaticRoute(meta);
}
Also used : StaticRoute(org.webpieces.router.impl.StaticRoute) RouteMeta(org.webpieces.router.impl.RouteMeta) UrlPath(org.webpieces.router.impl.UrlPath)

Example 2 with StaticRoute

use of org.webpieces.router.impl.StaticRoute in project webpieces by deanhiller.

the class TestCompressionCache method testModifyFileContentsButNotUrlPathFailure.

@Test
public void testModifyFileContentsButNotUrlPathFailure() throws IOException {
    File f = new File("src/test/resources/cacheTest1");
    File stagingDir = new File("output/staging");
    FileUtils.copyDirectory(f, stagingDir);
    List<StaticRoute> routes = runBasicServerOnce(stagingDir);
    File f2 = new File("src/test/resources/cacheTest2");
    FileUtils.deleteDirectory(stagingDir);
    //do not preserve dates here...
    FileUtils.copyDirectory(f2, stagingDir, false);
    try {
        cache.setupCache(routes);
        Assert.fail("should have failed since file contents changed and url path didn't which would have broken web app customers");
    } catch (IllegalStateException e) {
    }
}
Also used : StaticRoute(org.webpieces.router.impl.StaticRoute) File(java.io.File) Test(org.junit.Test)

Example 3 with StaticRoute

use of org.webpieces.router.impl.StaticRoute in project webpieces by deanhiller.

the class TestCompressionCache method testStartServerTwiceNoChanges.

@Test
public void testStartServerTwiceNoChanges() throws IOException {
    File f = new File("src/test/resources/cacheTest1");
    File stagingDir = new File("output/staging");
    FileUtils.copyDirectory(f, stagingDir);
    List<StaticRoute> routes = runBasicServerOnce(stagingDir);
    //if server is just restarted(no file changes), we should skip reading files...
    cache.setupCache(routes);
    Assert.assertEquals(0, proxy.getReadFiles().size());
    Assert.assertEquals(0, proxy.getCompressedFiles().size());
}
Also used : StaticRoute(org.webpieces.router.impl.StaticRoute) File(java.io.File) Test(org.junit.Test)

Example 4 with StaticRoute

use of org.webpieces.router.impl.StaticRoute in project webpieces by deanhiller.

the class TestCompressionCache method runBasicServerOnce.

private List<StaticRoute> runBasicServerOnce(File stagingDir) {
    List<StaticRoute> routes = new ArrayList<>();
    routes.add(new StaticRoute(new UrlPath("", "/public/"), stagingDir.getAbsolutePath() + "/", false, cacheDir));
    cache.setupCache(routes);
    Assert.assertEquals(2, proxy.getReadFiles().size());
    Assert.assertEquals(2, proxy.getCompressedFiles().size());
    proxy.clear();
    return routes;
}
Also used : StaticRoute(org.webpieces.router.impl.StaticRoute) UrlPath(org.webpieces.router.impl.UrlPath) ArrayList(java.util.ArrayList)

Example 5 with StaticRoute

use of org.webpieces.router.impl.StaticRoute in project webpieces by deanhiller.

the class ProdCompressionCacheSetup method setupCache.

public void setupCache(List<StaticRoute> staticRoutes) {
    if (config.getCachedCompressedDirectory() == null) {
        log.info("NOT setting up compressed cached directory so performance will not be as good");
        return;
    }
    log.info("setting up compressed cache directories");
    for (StaticRoute route : staticRoutes) {
        createCache(route);
    }
    log.info("all cached directories setup");
}
Also used : StaticRoute(org.webpieces.router.impl.StaticRoute)

Aggregations

StaticRoute (org.webpieces.router.impl.StaticRoute)7 File (java.io.File)4 Test (org.junit.Test)4 UrlPath (org.webpieces.router.impl.UrlPath)3 ArrayList (java.util.ArrayList)2 RouteMeta (org.webpieces.router.impl.RouteMeta)1