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;
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations