Esempio n. 1
0
  public void start() throws Exception {
    webRoot = FileUtil.createTempDirectory("jodd-http", "test");
    webRoot.deleteOnExit();

    // web-inf

    File webInfFolder = new File(webRoot, "WEB-INF");
    webInfFolder.mkdir();

    // web.xml

    URL webXmlUrl = TestServer.class.getResource("web.xml");
    File webXmlFile = FileUtil.toFile(webXmlUrl);

    FileUtil.copy(webXmlFile, webInfFolder);

    // lib folder

    File libFolder = new File(webInfFolder, "lib");
    libFolder.mkdir();

    // classes

    File classes = new File(webInfFolder, "classes/jodd/http");
    classes.mkdirs();

    URL echoServletUrl = TestServer.class.getResource("EchoServlet.class");
    File echoServletFile = FileUtil.toFile(echoServletUrl);
    FileUtil.copyFileToDir(echoServletFile, classes);

    echoServletUrl = TestServer.class.getResource("Echo2Servlet.class");
    echoServletFile = FileUtil.toFile(echoServletUrl);
    FileUtil.copyFileToDir(echoServletFile, classes);
  }
Esempio n. 2
0
  protected void prepareWebApplication() throws Exception {
    webRoot = FileUtil.createTempDirectory("jodd-madvoc", "test-int");
    webRoot.deleteOnExit();

    // web-inf

    File webInfFolder = new File(webRoot, "WEB-INF");
    webInfFolder.mkdir();

    // web.xml

    URL webXmlUrl = TestServer.class.getResource("web-test-int.xml");
    File webXmlFile = FileUtil.toFile(webXmlUrl);

    FileUtil.copyFile(webXmlFile, new File(webInfFolder, "web.xml"));

    // jsp

    File jspFolder = new File(webXmlFile.getParent(), "jsp");
    FileUtil.copyDir(jspFolder, webRoot);

    // lib folder

    File libFolder = new File(webInfFolder, "lib");
    libFolder.mkdir();

    // classes

    File classes = new File(webInfFolder, "classes");
    classes.mkdirs();

    // classes/madvoc.props

    URL madvocPropsUrl = TestServer.class.getResource("madvoc.props");
    File madvocPropsFile = FileUtil.toFile(madvocPropsUrl);

    FileUtil.copyFileToDir(madvocPropsFile, classes);
  }
Esempio n. 3
0
  /**
   * Returns default class path from all available <code>URLClassLoader</code> in classloader
   * hierarchy. The following is added to the classpath list:
   *
   * <ul>
   *   <li>file URLs from <code>URLClassLoader</code> (other URL protocols are ignored)
   *   <li>inner entries from containing <b>manifest</b> files (if exist)
   *   <li>bootstrap classpath
   * </ul>
   */
  public static File[] getDefaultClasspath(ClassLoader classLoader) {
    Set<File> classpaths = new TreeSet<>();

    while (classLoader != null) {
      if (classLoader instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) classLoader).getURLs();
        for (URL u : urls) {
          File f = FileUtil.toFile(u);
          if ((f != null) && f.exists()) {
            try {
              f = f.getCanonicalFile();

              boolean newElement = classpaths.add(f);
              if (newElement) {
                addInnerClasspathItems(classpaths, f);
              }
            } catch (IOException ignore) {
            }
          }
        }
      }
      classLoader = classLoader.getParent();
    }

    String bootstrap = SystemUtil.getSunBootClassPath();
    if (bootstrap != null) {
      String[] bootstrapFiles = StringUtil.splitc(bootstrap, File.pathSeparatorChar);
      for (String bootstrapFile : bootstrapFiles) {
        File f = new File(bootstrapFile);
        if (f.exists()) {
          try {
            f = f.getCanonicalFile();

            boolean newElement = classpaths.add(f);
            if (newElement) {
              addInnerClasspathItems(classpaths, f);
            }
          } catch (IOException ignore) {
          }
        }
      }
    }

    File[] result = new File[classpaths.size()];
    return classpaths.toArray(result);
  }