Search in sources :

Example 1 with JspRuntimeContext

use of org.apache.jasper.compiler.JspRuntimeContext in project tomcat by apache.

the class JspServlet method init.

/*
     * Initializes this JspServlet.
     */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    this.config = config;
    this.context = config.getServletContext();
    // Initialize the JSP Runtime Context
    // Check for a custom Options implementation
    String engineOptionsName = config.getInitParameter("engineOptionsClass");
    if (Constants.IS_SECURITY_ENABLED && engineOptionsName != null) {
        log.info(Localizer.getMessage("jsp.info.ignoreSetting", "engineOptionsClass", engineOptionsName));
        engineOptionsName = null;
    }
    if (engineOptionsName != null) {
        // Instantiate the indicated Options implementation
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class<?> engineOptionsClass = loader.loadClass(engineOptionsName);
            Class<?>[] ctorSig = { ServletConfig.class, ServletContext.class };
            Constructor<?> ctor = engineOptionsClass.getConstructor(ctorSig);
            Object[] args = { config, context };
            options = (Options) ctor.newInstance(args);
        } catch (Throwable e) {
            e = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(e);
            // Need to localize this.
            log.warn("Failed to load engineOptionsClass", e);
            // Use the default Options implementation
            options = new EmbeddedServletOptions(config, context);
        }
    } else {
        // Use the default Options implementation
        options = new EmbeddedServletOptions(config, context);
    }
    rctxt = new JspRuntimeContext(context, options);
    if (config.getInitParameter("jspFile") != null) {
        jspFile = config.getInitParameter("jspFile");
        try {
            if (null == context.getResource(jspFile)) {
                return;
            }
        } catch (MalformedURLException e) {
            throw new ServletException("cannot locate jsp file", e);
        }
        try {
            if (SecurityUtil.isPackageProtectionEnabled()) {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                    @Override
                    public Object run() throws IOException, ServletException {
                        serviceJspFile(null, null, jspFile, true);
                        return null;
                    }
                });
            } else {
                serviceJspFile(null, null, jspFile, true);
            }
        } catch (IOException e) {
            throw new ServletException("Could not precompile jsp: " + jspFile, e);
        } catch (PrivilegedActionException e) {
            Throwable t = e.getCause();
            if (t instanceof ServletException)
                throw (ServletException) t;
            throw new ServletException("Could not precompile jsp: " + jspFile, e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString()));
        log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) JspRuntimeContext(org.apache.jasper.compiler.JspRuntimeContext) EmbeddedServletOptions(org.apache.jasper.EmbeddedServletOptions)

Example 2 with JspRuntimeContext

use of org.apache.jasper.compiler.JspRuntimeContext in project tomcat by apache.

the class JspC method initServletContext.

protected void initServletContext(ClassLoader classLoader) throws IOException, JasperException {
    // TODO: should we use the Ant Project's log?
    PrintWriter log = new PrintWriter(System.out);
    URL resourceBase = new File(uriRoot).getCanonicalFile().toURI().toURL();
    context = new JspCServletContext(log, resourceBase, classLoader, isValidateXml(), isBlockExternal());
    if (isValidateTld()) {
        context.setInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM, "true");
    }
    initTldScanner(context, classLoader);
    try {
        scanner.scan();
    } catch (SAXException e) {
        throw new JasperException(e);
    }
    tldCache = new TldCache(context, scanner.getUriTldResourcePathMap(), scanner.getTldResourcePathTaglibXmlMap());
    context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME, tldCache);
    rctxt = new JspRuntimeContext(context, this);
    jspConfig = new JspConfig(context);
    tagPluginManager = new TagPluginManager(context);
}
Also used : TldCache(org.apache.jasper.compiler.TldCache) JspConfig(org.apache.jasper.compiler.JspConfig) JspRuntimeContext(org.apache.jasper.compiler.JspRuntimeContext) TagPluginManager(org.apache.jasper.compiler.TagPluginManager) File(java.io.File) JspCServletContext(org.apache.jasper.servlet.JspCServletContext) URL(java.net.URL) PrintWriter(java.io.PrintWriter) SAXException(org.xml.sax.SAXException)

Aggregations

JspRuntimeContext (org.apache.jasper.compiler.JspRuntimeContext)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ServletException (javax.servlet.ServletException)1 EmbeddedServletOptions (org.apache.jasper.EmbeddedServletOptions)1 JspConfig (org.apache.jasper.compiler.JspConfig)1 TagPluginManager (org.apache.jasper.compiler.TagPluginManager)1 TldCache (org.apache.jasper.compiler.TldCache)1 JspCServletContext (org.apache.jasper.servlet.JspCServletContext)1 SAXException (org.xml.sax.SAXException)1