launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
changeset 1165 06e7a74c72cf
parent 1098 fcf1d05b0d39
child 1186 265edcee24ed
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Thu May 16 08:51:29 2013 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Tue May 28 21:49:38 2013 +0200
     1.3 @@ -61,8 +61,8 @@
     1.4  abstract class BaseHTTPLauncher extends Launcher implements Closeable, Callable<HttpServer> {
     1.5      static final Logger LOG = Logger.getLogger(BaseHTTPLauncher.class.getName());
     1.6      private static final InvocationContext END = new InvocationContext(null, null, null);
     1.7 -    private final Set<ClassLoader> loaders = new LinkedHashSet<>();
     1.8 -    private final BlockingQueue<InvocationContext> methods = new LinkedBlockingQueue<>();
     1.9 +    private final Set<ClassLoader> loaders = new LinkedHashSet<ClassLoader>();
    1.10 +    private final BlockingQueue<InvocationContext> methods = new LinkedBlockingQueue<InvocationContext>();
    1.11      private long timeOut;
    1.12      private final Res resources = new Res();
    1.13      private final String cmd;
    1.14 @@ -112,7 +112,7 @@
    1.15          server = s;
    1.16          try {
    1.17              launchServerAndBrwsr(s, simpleName);
    1.18 -        } catch (URISyntaxException | InterruptedException ex) {
    1.19 +        } catch (Exception ex) {
    1.20              throw new IOException(ex);
    1.21          }
    1.22      }
    1.23 @@ -124,7 +124,7 @@
    1.24          HttpServer s = initServer(dir.getPath(), false);
    1.25          try {
    1.26              launchServerAndBrwsr(s, startpage);
    1.27 -        } catch (URISyntaxException | InterruptedException ex) {
    1.28 +        } catch (Exception ex) {
    1.29              throw new IOException(ex);
    1.30          }
    1.31      }
    1.32 @@ -237,7 +237,7 @@
    1.33          
    1.34          conf.addHttpHandler(new HttpHandler() {
    1.35              int cnt;
    1.36 -            List<InvocationContext> cases = new ArrayList<>();
    1.37 +            List<InvocationContext> cases = new ArrayList<InvocationContext>();
    1.38              DynamicResourceHandler prev;
    1.39              @Override
    1.40              public void service(Request request, Response response) throws Exception {
    1.41 @@ -547,7 +547,8 @@
    1.42                  replace = args;
    1.43              }
    1.44              OutputStream os = response.getOutputStream();
    1.45 -            try (InputStream is = res.get(r)) {
    1.46 +            try { 
    1.47 +                InputStream is = res.get(r);
    1.48                  copyStream(is, os, request.getRequestURL().toString(), replace);
    1.49              } catch (IOException ex) {
    1.50                  response.setDetailMessage(ex.getLocalizedMessage());
    1.51 @@ -603,7 +604,9 @@
    1.52              if (res.startsWith("/")) {
    1.53                  res = res.substring(1);
    1.54              }
    1.55 -            try (InputStream is = loader.get(res)) {
    1.56 +            InputStream is = null;
    1.57 +            try {
    1.58 +                is = loader.get(res);
    1.59                  response.setContentType("text/javascript");
    1.60                  Writer w = response.getWriter();
    1.61                  w.append("[");
    1.62 @@ -628,6 +631,10 @@
    1.63                  response.setStatus(HttpStatus.NOT_FOUND_404);
    1.64                  response.setError();
    1.65                  response.setDetailMessage(ex.getMessage());
    1.66 +            } finally {
    1.67 +                if (is != null) {
    1.68 +                    is.close();
    1.69 +                }
    1.70              }
    1.71          }
    1.72      }