Search in sources :

Example 6 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class TagPluginManager method init.

private void init(ErrorDispatcher err) throws JasperException {
    if (initialized)
        return;
    String blockExternalString = ctxt.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }
    TagPluginParser parser;
    ClassLoader original;
    if (Constants.IS_SECURITY_ENABLED) {
        PrivilegedGetTccl pa = new PrivilegedGetTccl();
        original = AccessController.doPrivileged(pa);
    } else {
        original = Thread.currentThread().getContextClassLoader();
    }
    try {
        if (Constants.IS_SECURITY_ENABLED) {
            PrivilegedSetTccl pa = new PrivilegedSetTccl(TagPluginManager.class.getClassLoader());
            AccessController.doPrivileged(pa);
        } else {
            Thread.currentThread().setContextClassLoader(TagPluginManager.class.getClassLoader());
        }
        parser = new TagPluginParser(ctxt, blockExternal);
        Enumeration<URL> urls = ctxt.getClassLoader().getResources(META_INF_JASPER_TAG_PLUGINS_XML);
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            parser.parse(url);
        }
        URL url = ctxt.getResource(TAG_PLUGINS_XML);
        if (url != null) {
            parser.parse(url);
        }
    } catch (IOException | SAXException e) {
        throw new JasperException(e);
    } finally {
        if (Constants.IS_SECURITY_ENABLED) {
            PrivilegedSetTccl pa = new PrivilegedSetTccl(original);
            AccessController.doPrivileged(pa);
        } else {
            Thread.currentThread().setContextClassLoader(original);
        }
    }
    Map<String, String> plugins = parser.getPlugins();
    tagPlugins = new HashMap<>(plugins.size());
    for (Map.Entry<String, String> entry : plugins.entrySet()) {
        try {
            String tagClass = entry.getKey();
            String pluginName = entry.getValue();
            Class<?> pluginClass = ctxt.getClassLoader().loadClass(pluginName);
            TagPlugin plugin = (TagPlugin) pluginClass.newInstance();
            tagPlugins.put(tagClass, plugin);
        } catch (Exception e) {
            err.jspError(e);
        }
    }
    initialized = true;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) JasperException(org.apache.jasper.JasperException) SAXException(org.xml.sax.SAXException) JasperException(org.apache.jasper.JasperException) PrivilegedGetTccl(org.apache.tomcat.util.security.PrivilegedGetTccl) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin) TagPluginParser(org.apache.tomcat.util.descriptor.tagplugin.TagPluginParser) HashMap(java.util.HashMap) Map(java.util.Map) PrivilegedSetTccl(org.apache.tomcat.util.security.PrivilegedSetTccl)

Example 7 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspCServletContext method buildMergedWebXml.

private WebXml buildMergedWebXml(boolean validate, boolean blockExternal) throws JasperException {
    WebXml webXml = new WebXml();
    WebXmlParser webXmlParser = new WebXmlParser(validate, validate, blockExternal);
    // Use this class's classloader as Ant will have set the TCCL to its own
    webXmlParser.setClassLoader(getClass().getClassLoader());
    try {
        URL url = getResource(org.apache.tomcat.util.descriptor.web.Constants.WEB_XML_LOCATION);
        if (!webXmlParser.parseWebXml(url, webXml, false)) {
            throw new JasperException(Localizer.getMessage("jspc.error.invalidWebXml"));
        }
    } catch (IOException e) {
        throw new JasperException(e);
    }
    // if the application is metadata-complete then we can skip fragment processing
    if (webXml.isMetadataComplete()) {
        return webXml;
    }
    // If an empty absolute ordering element is present, fragment processing
    // may be skipped.
    Set<String> absoluteOrdering = webXml.getAbsoluteOrdering();
    if (absoluteOrdering != null && absoluteOrdering.isEmpty()) {
        return webXml;
    }
    Map<String, WebXml> fragments = scanForFragments(webXmlParser);
    Set<WebXml> orderedFragments = WebXml.orderWebFragments(webXml, fragments, this);
    // JspC is not affected by annotations so skip that processing, proceed to merge
    webXml.merge(orderedFragments);
    return webXml;
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) WebXmlParser(org.apache.tomcat.util.descriptor.web.WebXmlParser) URL(java.net.URL)

Example 8 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspCServletContext method scanForFragments.

private Map<String, WebXml> scanForFragments(WebXmlParser webXmlParser) throws JasperException {
    StandardJarScanner scanner = new StandardJarScanner();
    // TODO - enabling this means initializing the classloader first in JspC
    scanner.setScanClassPath(false);
    // TODO - configure filter rules from Ant rather then system properties
    scanner.setJarScanFilter(new StandardJarScanFilter());
    FragmentJarScannerCallback callback = new FragmentJarScannerCallback(webXmlParser, false, true);
    scanner.scan(JarScanType.PLUGGABILITY, this, callback);
    if (!callback.isOk()) {
        throw new JasperException(Localizer.getMessage("jspc.error.invalidFragment"));
    }
    return callback.getFragments();
}
Also used : JasperException(org.apache.jasper.JasperException) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) FragmentJarScannerCallback(org.apache.tomcat.util.descriptor.web.FragmentJarScannerCallback) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter)

Example 9 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspServletWrapper method loadTagFile.

/**
     * Compile (if needed) and load a tag file.
     * @return the loaded class
     * @throws JasperException Error compiling or loading tag file
     */
public Class<?> loadTagFile() throws JasperException {
    try {
        if (ctxt.isRemoved()) {
            throw new FileNotFoundException(jspUri);
        }
        if (options.getDevelopment() || firstTime) {
            synchronized (this) {
                firstTime = false;
                ctxt.compile();
            }
        } else {
            if (compileException != null) {
                throw compileException;
            }
        }
        if (reload) {
            tagHandlerClass = ctxt.load();
            reload = false;
        }
    } catch (FileNotFoundException ex) {
        throw new JasperException(ex);
    }
    return tagHandlerClass;
}
Also used : JasperException(org.apache.jasper.JasperException) FileNotFoundException(java.io.FileNotFoundException)

Example 10 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, long value) throws JasperException {
    try {
        Method method = getWriteMethod(bean.getClass(), prop);
        method.invoke(bean, new Object[] { Long.valueOf(value) });
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
}
Also used : JasperException(org.apache.jasper.JasperException) Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Aggregations

JasperException (org.apache.jasper.JasperException)35 IOException (java.io.IOException)29 ServletException (javax.servlet.ServletException)20 JspException (javax.servlet.jsp.JspException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)7 HashMap (java.util.HashMap)3 UnavailableException (javax.servlet.UnavailableException)3 TagInfo (javax.servlet.jsp.tagext.TagInfo)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Map (java.util.Map)2 Servlet (javax.servlet.Servlet)2 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)2 PropertyEditor (java.beans.PropertyEditor)1 BufferedOutputStream (java.io.BufferedOutputStream)1