When querying manifests, return them as array of bytes closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 05 May 2014 13:49:05 +0200
branchclosure
changeset 153045c50b9c7dc4
parent 1529 9afa6856382c
child 1531 ce3b83777055
When querying manifests, return them as array of bytes
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon May 05 12:58:10 2014 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon May 05 13:49:05 2014 +0200
     1.3 @@ -35,6 +35,7 @@
     1.4  import java.util.ArrayList;
     1.5  import java.util.Arrays;
     1.6  import java.util.Enumeration;
     1.7 +import java.util.HashSet;
     1.8  import java.util.LinkedHashSet;
     1.9  import java.util.List;
    1.10  import java.util.Set;
    1.11 @@ -579,8 +580,12 @@
    1.12      }
    1.13  
    1.14      final class Res {
    1.15 -        String compileJar(JarFile jar) throws IOException {
    1.16 -            return BaseHTTPLauncher.this.compileJar(jar);
    1.17 +        private final Set<URL> ignore = new HashSet<URL>();
    1.18 +        
    1.19 +        String compileJar(JarFile jar, URL jarURL) throws IOException {
    1.20 +            String ret = BaseHTTPLauncher.this.compileJar(jar);
    1.21 +            ignore.add(jarURL);
    1.22 +            return ret;
    1.23          }
    1.24          String compileFromClassPath(URL f) throws IOException {
    1.25              return BaseHTTPLauncher.this.compileFromClassPath(f, this);
    1.26 @@ -618,6 +623,12 @@
    1.27                          // module is not compiled with target 1.6, currently
    1.28                          continue;
    1.29                      }
    1.30 +                    if (now.getProtocol().equals("jar")) {
    1.31 +                        JarURLConnection juc = (JarURLConnection) now.openConnection();
    1.32 +                        if (ignore.contains(juc.getJarFileURL())) {
    1.33 +                            continue;
    1.34 +                        }
    1.35 +                    }
    1.36                      if (--skip < 0) {
    1.37                          return now;
    1.38                      }
    1.39 @@ -730,11 +741,11 @@
    1.40              String skip = request.getParameter("skip");
    1.41              int skipCnt = skip == null ? 0 : Integer.parseInt(skip);
    1.42              URL url = loader.get(res, skipCnt);
    1.43 -            try {
    1.44 +            if (url != null && !res.equals("META-INF/MANIFEST.MF")) try {
    1.45                  response.setCharacterEncoding("UTF-8");
    1.46                  if (url.getProtocol().equals("jar")) {
    1.47                      JarURLConnection juc = (JarURLConnection) url.openConnection();
    1.48 -                    String s = loader.compileJar(juc.getJarFile());
    1.49 +                    String s = loader.compileJar(juc.getJarFile(), juc.getJarFileURL());
    1.50                      if (s != null) {
    1.51                          Writer w = response.getWriter();
    1.52                          w.append(s);
    1.53 @@ -753,18 +764,13 @@
    1.54                  }
    1.55              } catch (IOException ex) {
    1.56                  LOG.log(Level.SEVERE, "Cannot handle " + res, ex);
    1.57 -                throw ex;
    1.58              }
    1.59 -            Exception ex = new Exception("Won't server bytes of " + url);
    1.60 -            /*
    1.61 -            try (InputStream is = url.openStream()) {
    1.62 -=======
    1.63              InputStream is = null;
    1.64              try {
    1.65 -                String skip = request.getParameter("skip");
    1.66 -                int skipCnt = skip == null ? 0 : Integer.parseInt(skip);
    1.67 -                is = loader.get(res, skipCnt);
    1.68 ->>>>>>> other
    1.69 +                if (url == null) {
    1.70 +                    throw new IOException("Resource not found");
    1.71 +                }
    1.72 +                is = url.openStream();
    1.73                  response.setContentType("text/javascript");
    1.74                  Writer w = response.getWriter();
    1.75                  w.append("([");
    1.76 @@ -785,16 +791,15 @@
    1.77                      w.append(Integer.toString(b));
    1.78                  }
    1.79                  w.append("\n])");
    1.80 -            } catch (IOException ex) 
    1.81 -            */ {
    1.82 +            } catch (IOException ex) {
    1.83                  response.setStatus(HttpStatus.NOT_FOUND_404);
    1.84                  response.setError();
    1.85                  response.setDetailMessage(ex.getMessage());
    1.86 -            } /*finally {
    1.87 +            } finally {
    1.88                  if (is != null) {
    1.89                      is.close();
    1.90                  }
    1.91 -            }*/
    1.92 +            }
    1.93          }
    1.94  
    1.95      }
     2.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon May 05 12:58:10 2014 +0200
     2.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon May 05 13:49:05 2014 +0200
     2.3 @@ -95,11 +95,12 @@
     2.4          sb.append(
     2.5                "(function WrapperVM(global) {\n"
     2.6              + "  var cache = {};\n"
     2.7 +            + "  var empty = {};\n"
     2.8              + "  function ldCls(res, skip) {\n"
     2.9              + "    var c = cache[res];\n"
    2.10              + "    if (c) {\n"
    2.11 +            + "      if (c[skip] === empty) return null;\n"
    2.12              + "      if (c[skip]) return c[skip];\n"
    2.13 -            + "      if (c[skip] === null) return null;\n"
    2.14              + "    } else {\n"
    2.15              + "      cache[res] = c = new Array();\n"
    2.16              + "    }\n"
    2.17 @@ -111,6 +112,7 @@
    2.18              + "      return null;\n"
    2.19              + "    }\n"
    2.20              + "    var arr = eval(request.responseText);\n"
    2.21 +            + "    if (arr === null) arr = empty;\n"
    2.22              + "    c[skip] = arr;\n"
    2.23              + "    return arr;\n"
    2.24              + "  }\n"