Ejemplo n.º 1
0
  /**
   * Method used by background thread to check the JSP dependencies registered with this class for
   * JSP's.
   */
  public void checkCompile() {

    if (lastCheck < 0) {
      // Checking was disabled
      return;
    }
    long now = System.currentTimeMillis();
    if (now > (lastCheck + (options.getCheckInterval() * 1000L))) {
      lastCheck = now;
    } else {
      return;
    }

    Object[] wrappers = jsps.values().toArray();
    for (int i = 0; i < wrappers.length; i++) {
      JspServletWrapper jsw = (JspServletWrapper) wrappers[i];
      JspCompilationContext ctxt = jsw.getJspEngineContext();
      // JspServletWrapper also synchronizes on this when
      // it detects it has to do a reload
      synchronized (jsw) {
        try {
          ctxt.compile();
        } catch (FileNotFoundException ex) {
          ctxt.incrementRemoved();
        } catch (Throwable t) {
          jsw.getServletContext().log("Background compile failed", t);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Create a JspRuntimeContext for a web application context.
   *
   * <p>Loads in any previously generated dependencies from file.
   *
   * @param context ServletContext for web application
   */
  public JspRuntimeContext(ServletContext context, Options options) {

    this.context = context;
    this.options = options;

    // Get the parent class loader
    parentClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
    if (parentClassLoader == null) {
      parentClassLoader = (URLClassLoader) this.getClass().getClassLoader();
    }

    if (log.isDebugEnabled()) {
      if (parentClassLoader != null) {
        log.debug(
            Localizer.getMessage(
                "jsp.message.parent_class_loader_is", parentClassLoader.toString()));
      } else {
        log.debug(Localizer.getMessage("jsp.message.parent_class_loader_is", "<none>"));
      }
    }

    initClassPath();

    if (context instanceof org.apache.jasper.servlet.JspCServletContext) {
      return;
    }

    if (Constants.IS_SECURITY_ENABLED) {
      initSecurity();
    }

    // If this web application context is running from a
    // directory, start the background compilation thread
    String appBase = context.getRealPath("/");
    if (!options.getDevelopment() && appBase != null && options.getCheckInterval() > 0) {
      lastCheck = System.currentTimeMillis();
    }
  }