use of org.apache.jasper.JspCompilationContext in project tomcat70 by apache.
the class TagFileProcessor method loadTagFile.
/**
* Compiles and loads a tagfile.
*/
private Class<?> loadTagFile(Compiler compiler, String tagFilePath, TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {
JarResource tagJarResouce = null;
if (tagFilePath.startsWith("/META-INF/")) {
tagJarResouce = compiler.getCompilationContext().getTldLocation(tagInfo.getTagLibrary().getURI()).getJarResource();
}
String wrapperUri;
if (tagJarResouce == null) {
wrapperUri = tagFilePath;
} else {
wrapperUri = tagJarResouce.getEntry(tagFilePath).toString();
}
JspCompilationContext ctxt = compiler.getCompilationContext();
JspRuntimeContext rctxt = ctxt.getRuntimeContext();
synchronized (rctxt) {
JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri);
if (wrapper == null) {
wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), tagJarResouce);
rctxt.addWrapper(wrapperUri, wrapper);
// Use same classloader and classpath for compiling tag files
wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
} else {
// Make sure that JspCompilationContext gets the latest TagInfo
// for the tag file. TagInfo instance was created the last
// time the tag file was scanned for directives, and the tag
// file may have been modified since then.
wrapper.getJspEngineContext().setTagInfo(tagInfo);
}
Class<?> tagClazz;
int tripCount = wrapper.incTripCount();
try {
if (tripCount > 0) {
// When tripCount is greater than zero, a circular
// dependency exists. The circularly dependent tag
// file is compiled in prototype mode, to avoid infinite
// recursion.
JspServletWrapper tempWrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), tagJarResouce);
// Use same classloader and classpath for compiling tag files
tempWrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
tagClazz = tempWrapper.loadTagFilePrototype();
tempVector.add(tempWrapper.getJspEngineContext().getCompiler());
} else {
tagClazz = wrapper.loadTagFile();
}
} finally {
wrapper.decTripCount();
}
// can only be obtained from the tag instance.
try {
Object tagIns = tagClazz.newInstance();
if (tagIns instanceof JspSourceDependent) {
Iterator<Entry<String, Long>> iter = ((JspSourceDependent) tagIns).getDependants().entrySet().iterator();
while (iter.hasNext()) {
Entry<String, Long> entry = iter.next();
parentPageInfo.addDependant(entry.getKey(), entry.getValue());
}
}
} catch (Exception e) {
// ignore errors
}
return tagClazz;
}
}
use of org.apache.jasper.JspCompilationContext in project tomcat by apache.
the class TagFileProcessor method loadTagFile.
/**
* Compiles and loads a tagfile.
*/
private Class<?> loadTagFile(Compiler compiler, String tagFilePath, TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {
Jar tagJar = null;
Jar tagJarOriginal = null;
try {
if (tagFilePath.startsWith("/META-INF/")) {
try {
tagJar = compiler.getCompilationContext().getTldResourcePath(tagInfo.getTagLibrary().getURI()).openJar();
} catch (IOException ioe) {
throw new JasperException(ioe);
}
}
String wrapperUri;
if (tagJar == null) {
wrapperUri = tagFilePath;
} else {
wrapperUri = tagJar.getURL(tagFilePath);
}
JspCompilationContext ctxt = compiler.getCompilationContext();
JspRuntimeContext rctxt = ctxt.getRuntimeContext();
synchronized (rctxt) {
JspServletWrapper wrapper = null;
try {
wrapper = rctxt.getWrapper(wrapperUri);
if (wrapper == null) {
wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), tagJar);
// Use same classloader and classpath for compiling tag files
wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
rctxt.addWrapper(wrapperUri, wrapper);
} else {
// Make sure that JspCompilationContext gets the latest TagInfo
// for the tag file. TagInfo instance was created the last
// time the tag file was scanned for directives, and the tag
// file may have been modified since then.
wrapper.getJspEngineContext().setTagInfo(tagInfo);
// This compilation needs to use the current tagJar.
// Compilation may be nested in which case the old tagJar
// will need to be restored
tagJarOriginal = wrapper.getJspEngineContext().getTagFileJar();
wrapper.getJspEngineContext().setTagFileJar(tagJar);
}
Class<?> tagClazz;
int tripCount = wrapper.incTripCount();
try {
if (tripCount > 0) {
// When tripCount is greater than zero, a circular
// dependency exists. The circularly dependent tag
// file is compiled in prototype mode, to avoid infinite
// recursion.
JspServletWrapper tempWrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), tagJar);
// Use same classloader and classpath for compiling tag files
tempWrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
tagClazz = tempWrapper.loadTagFilePrototype();
tempVector.add(tempWrapper.getJspEngineContext().getCompiler());
} else {
tagClazz = wrapper.loadTagFile();
}
} finally {
wrapper.decTripCount();
}
// can only be obtained from the tag instance.
try {
Object tagIns = tagClazz.getConstructor().newInstance();
if (tagIns instanceof JspSourceDependent) {
for (Entry<String, Long> entry : ((JspSourceDependent) tagIns).getDependants().entrySet()) {
parentPageInfo.addDependant(entry.getKey(), entry.getValue());
}
}
} catch (RuntimeException | ReflectiveOperationException e) {
// ignore errors
}
return tagClazz;
} finally {
if (wrapper != null && tagJarOriginal != null) {
wrapper.getJspEngineContext().setTagFileJar(tagJarOriginal);
}
}
}
} finally {
if (tagJar != null) {
tagJar.close();
}
}
}
use of org.apache.jasper.JspCompilationContext in project tomcat70 by apache.
the class JspRuntimeContext method checkCompile.
/**
* Method used by background thread to check the JSP dependencies
* registered with this class for JSP's.
*/
public void checkCompile() {
if (lastCompileCheck < 0) {
// Checking was disabled
return;
}
long now = System.currentTimeMillis();
if (now > (lastCompileCheck + (options.getCheckInterval() * 1000L))) {
lastCompileCheck = 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();
// it detects it has to do a reload
synchronized (jsw) {
try {
ctxt.compile();
} catch (FileNotFoundException ex) {
ctxt.incrementRemoved();
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
jsw.getServletContext().log("Background compile failed", t);
}
}
}
}
use of org.apache.jasper.JspCompilationContext in project tomcat by apache.
the class JspRuntimeContext method checkCompile.
/**
* Method used by background thread to check the JSP dependencies
* registered with this class for JSP's.
*/
public void checkCompile() {
if (lastCompileCheck < 0) {
// Checking was disabled
return;
}
long now = System.currentTimeMillis();
if (now > (lastCompileCheck + (options.getCheckInterval() * 1000L))) {
lastCompileCheck = now;
} else {
return;
}
List<JspServletWrapper> wrappersToReload = new ArrayList<>();
// Tell JspServletWrapper to ignore the reload attribute while this
// check is in progress. See BZ 62603.
compileCheckInProgress = true;
Object[] wrappers = jsps.values().toArray();
for (Object wrapper : wrappers) {
JspServletWrapper jsw = (JspServletWrapper) wrapper;
JspCompilationContext ctxt = jsw.getJspEngineContext();
// Sync on JspServletWrapper when calling ctxt.compile()
synchronized (jsw) {
try {
ctxt.compile();
if (jsw.getReload()) {
wrappersToReload.add(jsw);
}
} catch (FileNotFoundException ex) {
ctxt.incrementRemoved();
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
jsw.getServletContext().log(Localizer.getMessage("jsp.error.backgroundCompilationFailed"), t);
}
}
}
// See BZ 62603.
// OK to process reload flag now.
compileCheckInProgress = false;
// Ensure all servlets and tags that need to be reloaded, are reloaded.
for (JspServletWrapper jsw : wrappersToReload) {
// Triggers reload
try {
if (jsw.isTagFile()) {
// conditions during the reload.
synchronized (this) {
jsw.loadTagFile();
}
} else {
jsw.getServlet();
}
} catch (ServletException e) {
jsw.getServletContext().log(Localizer.getMessage("jsp.error.reload"), e);
}
}
}
Aggregations