Old handlers are sometimes used even after remoteHttpHandler is called. Invalidate old handlers by forcing them to delegate to the latest one.
1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Thu Jun 27 06:59:33 2013 +0200
1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Thu Jun 27 10:05:00 2013 +0200
1.3 @@ -17,7 +17,6 @@
1.4 */
1.5 package org.apidesign.bck2brwsr.launcher;
1.6
1.7 -import java.io.BufferedReader;
1.8 import java.io.ByteArrayInputStream;
1.9 import java.io.Closeable;
1.10 import java.io.File;
1.11 @@ -46,7 +45,6 @@
1.12 import java.util.logging.Logger;
1.13 import org.apidesign.bck2brwsr.launcher.InvocationContext.Resource;
1.14 import org.glassfish.grizzly.PortRange;
1.15 -import org.glassfish.grizzly.http.Method;
1.16 import org.glassfish.grizzly.http.server.HttpHandler;
1.17 import org.glassfish.grizzly.http.server.HttpServer;
1.18 import org.glassfish.grizzly.http.server.NetworkListener;
1.19 @@ -183,6 +181,7 @@
1.20 class DynamicResourceHandler extends HttpHandler {
1.21 private final InvocationContext ic;
1.22 private int resourcesCount;
1.23 + DynamicResourceHandler delegate;
1.24 public DynamicResourceHandler(InvocationContext ic) {
1.25 this.ic = ic;
1.26 for (Resource r : ic.resources) {
1.27 @@ -190,12 +189,18 @@
1.28 }
1.29 }
1.30
1.31 - public void close() {
1.32 + public void close(DynamicResourceHandler del) {
1.33 conf.removeHttpHandler(this);
1.34 + delegate = del;
1.35 }
1.36
1.37 @Override
1.38 public void service(Request request, Response response) throws Exception {
1.39 + if (delegate != null) {
1.40 + delegate.service(request, response);
1.41 + return;
1.42 + }
1.43 +
1.44 if ("/dynamic".equals(request.getRequestURI())) {
1.45 String mimeType = request.getParameter("mimeType");
1.46 List<String> params = new ArrayList<String>();
1.47 @@ -297,11 +302,6 @@
1.48 }
1.49 }
1.50
1.51 - if (prev != null) {
1.52 - prev.close();
1.53 - prev = null;
1.54 - }
1.55 -
1.56 if (mi == null) {
1.57 mi = methods.take();
1.58 caseNmbr = cnt++;
1.59 @@ -313,8 +313,11 @@
1.60 LOG.log(Level.INFO, "End of data reached. Exiting.");
1.61 return;
1.62 }
1.63 -
1.64 - prev = new DynamicResourceHandler(mi);
1.65 + final DynamicResourceHandler newRH = new DynamicResourceHandler(mi);
1.66 + if (prev != null) {
1.67 + prev.close(newRH);
1.68 + }
1.69 + prev = newRH;
1.70 conf.addHttpHandler(prev, "/dynamic");
1.71
1.72 cases.add(mi);