diff -r a07253cf2ca4 -r 4af0d3dedb9d launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Jan 31 16:58:27 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu Jan 31 17:39:47 2013 +0100 @@ -147,13 +147,40 @@ private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException { wait = new CountDownLatch(1); server = initServer(".", true); - ServerConfiguration conf = server.getServerConfiguration(); + final ServerConfiguration conf = server.getServerConfiguration(); + + class DynamicResourceHandler extends HttpHandler { + private final InvocationContext ic; + public DynamicResourceHandler(InvocationContext ic) { + if (ic == null || ic.httpPath == null) { + throw new NullPointerException(); + } + this.ic = ic; + conf.addHttpHandler(this, ic.httpPath); + } + + public void close() { + conf.removeHttpHandler(this); + } + + @Override + public void service(Request request, Response response) throws Exception { + if (ic.httpPath.equals(request.getRequestURI())) { + LOG.log(Level.INFO, "Serving HttpResource for {0}", request.getRequestURI()); + response.setContentType(ic.httpType); + response.getWriter().write(ic.httpContent); + } + } + } + conf.addHttpHandler(new Page(resources, "org/apidesign/bck2brwsr/launcher/harness.xhtml" ), "/execute"); + conf.addHttpHandler(new HttpHandler() { int cnt; List cases = new ArrayList<>(); + DynamicResourceHandler prev; @Override public void service(Request request, Response response) throws Exception { String id = request.getParameter("request"); @@ -165,6 +192,11 @@ cases.get(Integer.parseInt(id)).result(value, null); } + if (prev != null) { + prev.close(); + prev = null; + } + InvocationContext mi = methods.take(); if (mi == END) { response.getWriter().write(""); @@ -174,6 +206,10 @@ return; } + if (mi.httpPath != null) { + prev = new DynamicResourceHandler(mi); + } + cases.add(mi); final String cn = mi.clazz.getName(); final String mn = mi.methodName;