# HG changeset patch # User Jaroslav Tulach # Date 1365006229 -7200 # Node ID a85e27899a809bb72dbe03a632bb634a3bd0e66a # Parent c8ddf2e0c1697c43bb66753a359211134ce5f084 #4858: Let the server provide all resources around the startpage diff -r c8ddf2e0c169 -r a85e27899a80 rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Wed Apr 03 18:21:42 2013 +0200 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Wed Apr 03 18:23:49 2013 +0200 @@ -98,9 +98,9 @@ } HttpServer s = initServer(".", true); int last = startpage.lastIndexOf('/'); + String prefix = startpage.substring(0, last); String simpleName = startpage.substring(last); - s.getServerConfiguration().addHttpHandler(new Page(resources, startpage), simpleName); - s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/"); + s.getServerConfiguration().addHttpHandler(new SubTree(resources, prefix), "/"); try { launchServerAndBrwsr(s, simpleName); } catch (URISyntaxException | InterruptedException ex) { @@ -454,7 +454,7 @@ } private static class Page extends HttpHandler { - private final String resource; + final String resource; private final String[] args; private final Res res; @@ -466,10 +466,7 @@ @Override public void service(Request request, Response response) throws Exception { - String r = resource; - if (r == null) { - r = request.getHttpHandlerPath(); - } + String r = computePage(request); if (r.startsWith("/")) { r = r.substring(1); } @@ -493,6 +490,28 @@ response.setStatus(404); } } + + protected String computePage(Request request) { + String r = resource; + if (r == null) { + r = request.getHttpHandlerPath(); + } + return r; + } + } + + private static class SubTree extends Page { + + public SubTree(Res res, String resource, String... args) { + super(res, resource, args); + } + + @Override + protected String computePage(Request request) { + return resource + request.getHttpHandlerPath(); + } + + } private static class VM extends HttpHandler {