public URLConnection getResource(URL url) throws IOException {
    if (!"jndi".equals(url.getProtocol())) return null;

    // handle jndi:/server (single slash) parsing (gf)
    String file = url.getFile();

    if ("".equals(url.getHost()) && file.startsWith("/server")) {
      file = file.substring(7, file.length());

      if (file.startsWith(getContextPath())) file = file.substring(getContextPath().length());
      else {
        // server/102p
        int p = file.indexOf('/', 1);

        if (p > 0) {
          String contextPath = file.substring(0, p);
          WebApp webApp = (WebApp) getContext(contextPath);

          if (webApp != null) return webApp.getResource(url);
        }
      }
    }

    String realPath = getRealPath(file);
    Path rootDirectory = getRootDirectory();
    Path path = rootDirectory.lookup(realPath);

    if (path.exists()) return new URL(path.getURL()).openConnection();

    int fileIdx;

    URLConnection connection = null;

    if (file.length() > 1 && (fileIdx = file.indexOf("/", 1)) > -1) {
      String context = file.substring(0, file.indexOf("/", 1));

      if (context.equals(getContextPath())) { // disable cross-context lookup

        file = file.substring(fileIdx, file.length());
        realPath = getRealPath(file);
        path = rootDirectory.lookup(realPath);

        if (path.exists()) connection = new URL(path.getURL()).openConnection();
      }
    }

    if (connection != null) return connection;

    return new FileNotFoundURLConnection(url);
  }