Пример #1
0
  void configure(Configuration configuration) {
    long start = System.nanoTime();
    initBaseDir(configuration);
    Digester digester = new FakeCatalina().createStartDigester();
    digester.push(this);

    URL tomcatResource = configuration.getConfigurationURL();
    if (tomcatResource == null) {
      tomcatResource = getClass().getResource("/tomcat-server.xml");
    }

    File configurationFile = new File(configuration.getConfigurationDir(), SERVER_CONFIG_FILE_NAME);
    if (configurationFile.exists()) {
      try {
        tomcatResource = configurationFile.toURI().toURL();
      } catch (MalformedURLException e) {
        LOG.error("Exception while starting Tomcat:", e);
        throw new RuntimeException("Exception while starting Tomcat", e);
      }
    }
    if (tomcatResource != null) {
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        LOG.debug("Configure using resource " + tomcatResource);

        digester.parse(tomcatResource.openStream());
        long elapsed = start - System.nanoTime();
        if (LOG.isInfoEnabled()) {
          LOG.info("configuration processed in {} ms", (elapsed / 1000000));
        }
      } catch (IOException e) {
        LOG.error("Exception while starting Tomcat:", e);
        throw new RuntimeException("Exception while starting Tomcat", e);
      } catch (SAXException e) {
        LOG.error("Exception while starting Tomcat:", e);
        throw new RuntimeException("Exception while starting Tomcat", e);
      } finally {
        Thread.currentThread().setContextClassLoader(loader);
      }
    }

    mergeConfiguration(configuration);
  }