WebModuleListenerpublic final class WebModuleListener extends Object implements org.apache.catalina.LifecycleListenerStartup event listener for a Context that configures the properties
of that Jsp Servlet from sun-web.xml |
Fields Summary |
---|
private static Logger | _loggerThe logger used to log messages | private static boolean | _debugLogThis indicates whether debug logging is on or not | private String | instanceClassPathThe instance classpath, which is composed of the pathnames of
domain_root/lib/classes and domain_root/lib/[*.jar|*.zip] (in this
order), separated by the path-separator character. | private com.sun.enterprise.deployment.WebBundleDescriptor | wbdDescriptor object associated with this web application.
Used for loading persistence units. | private String | explodedLocationThe exploded location for this web module.
Note this is not the generated location. |
Methods Summary |
---|
private void | configureDefaultServlet(WebModule webModule)Configures the given web module's DefaultServlet with the
applicable web properties from sun-web.xml.
// Find the DefaultServlet
Wrapper wrapper = (Wrapper)webModule.findChild("default");
if (wrapper == null) {
return;
}
String servletClass = wrapper.getServletClass();
if (servletClass == null
|| !servletClass.equals(Globals.DEFAULT_SERVLET_CLASS_NAME)) {
return;
}
String fileEncoding = webModule.getFileEncoding();
if (fileEncoding != null) {
wrapper.addInitParameter("fileEncoding", fileEncoding);
}
| private void | configureJspParameters(WebModule webModule)Configure the jsp config settings for the jspServlet using the values
in sun-web.xml's jsp-config
SunWebApp bean = webModule.getIasWebAppConfigBean();
// Find the default jsp servlet
String name = webModule.findServletMapping(Constants.JSP_URL_PATTERN);
Wrapper wrapper = (Wrapper)webModule.findChild(name);
if (wrapper == null)
return;
String servletClass = wrapper.getServletClass();
// If the jsp maps to the default JspServlet, then add
// the init parameters
if (servletClass != null
&& servletClass.equals(Constants.APACHE_JSP_SERVLET_CLASS)) {
if (webModule.getTldValidation()) {
wrapper.addInitParameter("enableTldValidation", "true");
}
if (bean != null && bean.getJspConfig() != null) {
WebProperty[] props = bean.getJspConfig().getWebProperty();
for (int i = 0; i < props.length; i++) {
String pname = props[i].getAttributeValue("name");
String pvalue = props[i].getAttributeValue("value");
if (_debugLog) {
_logger.fine("jsp-config property for ["
+ webModule.getID() + "] is [" + pname
+ "] = [" + pvalue + "]");
}
wrapper.addInitParameter(pname, pvalue);
}
}
// Override any log setting with the container wide logging level
wrapper.addInitParameter("logVerbosityLevel",getJasperLogLevel());
wrapper.addInitParameter("com.sun.appserv.jsp.resource.injector",
ResourceInjectorImpl.class.getName());
// START SJSAS 6311155
String sysClassPath = ASClassLoaderUtil.getWebModuleClassPath(webModule.getID());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" sysClasspath for " + webModule.getID() + " is \n"
+ sysClassPath + "\n");
}
if (instanceClassPath != null
&& instanceClassPath.length() > 0) {
sysClassPath += instanceClassPath;
}
wrapper.addInitParameter("com.sun.appserv.jsp.classpath",
sysClassPath);
// END SJSAS 6311155
}
| private java.lang.String | getJasperLogLevel()Determine the debug setting for JspServlet based on the iAS log
level.
Level level = _logger.getLevel();
if (level.equals((Level)IASLevel.FATAL))
return "fatal";
else if (level.equals(Level.WARNING))
return "warning";
else if (level.equals(Level.FINE))
return "information";
else if (level.equals(Level.FINER) || level.equals(Level.FINEST))
return "debug";
else
return "warning";
| public void | lifecycleEvent(org.apache.catalina.LifecycleEvent event)Process the START event for an associated WebModule
if (_logger == null) {
_logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
_debugLog = _logger.isLoggable(Level.FINE);
}
WebModule webModule;
// Identify the context we are associated with
try {
webModule = (WebModule) event.getLifecycle();
} catch (ClassCastException e) {
_logger.log(Level.WARNING, "webmodule.listener.classcastException",
event.getLifecycle());
return;
}
// Process the event that has occurred
if (event.getType().equals(Lifecycle.START_EVENT)) {
// post processing DOL object for standalone web module
if (wbd != null && wbd.getApplication() != null &&
wbd.getApplication().isVirtual()) {
wbd.setClassLoader(webModule.getLoader().getClassLoader());
wbd.visit((WebBundleVisitor) new WebValidatorWithCL());
}
loadPersistenceUnits(webModule);
configureDefaultServlet(webModule);
configureJspParameters(webModule);
startCacheManager(webModule);
} else if (event.getType().equals(Lifecycle.STOP_EVENT)) {
unloadPersistenceUnits(webModule);
stopCacheManager(webModule);
}
| private void | loadPersistenceUnits(WebModule webModule)
_logger.logp(Level.FINE, "WebModuleListener", "loadPersistenceUnits",
"wbd = {0} for {1}", new Object[]{wbd, webModule.getName()});
if(wbd == null) {
// for some system app like adminGUI, wbd is null
return;
}
final Application application = wbd.getApplication();
// load PUs only for standaalone wars.
// embedded wars are taken care of in ApplicationLoader.
if(application != null && application.isVirtual()) {
try{
new PersistenceUnitLoaderImpl().load(new ApplicationInfoImpl(
explodedLocation, wbd, webModule));
} catch(Exception e){
throw new RuntimeException(e);
}
}
| private void | startCacheManager(WebModule webModule)
SunWebApp bean = webModule.getIasWebAppConfigBean();
// Configure the cache, cache-mapping and other settings
if (bean != null) {
CacheManager cm = null;
try {
cm = CacheModule.configureResponseCache(webModule, bean);
} catch (Exception ee) {
_logger.log(Level.WARNING,
"webmodule.listener.cachemgrException", ee);
}
if (cm != null) {
try {
// first start the CacheManager, if enabled
cm.start();
if (_debugLog) {
_logger.fine("Cache Manager started");
}
// set this manager as a context attribute so that
// caching filters/tags can find it
ServletContext ctxt = webModule.getServletContext();
ctxt.setAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME, cm);
} catch (LifecycleException ee) {
_logger.log(Level.WARNING, ee.getMessage(),
ee.getThrowable());
}
}
}
| private void | stopCacheManager(WebModule webModule)
ServletContext ctxt = webModule.getServletContext();
CacheManager cm = (CacheManager)ctxt.getAttribute(
CacheManager.CACHE_MANAGER_ATTR_NAME);
if (cm != null) {
try {
cm.stop();
if (_debugLog) {
_logger.fine("Cache Manager stopped");
}
ctxt.removeAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);
} catch (LifecycleException ee) {
_logger.log(Level.WARNING, ee.getMessage(), ee.getThrowable());
}
}
| private boolean | unloadPersistenceUnits(WebModule webModule)
_logger.logp(Level.FINE, "WebModuleListener", "unloadPersistenceUnits",
"wbd = {0} for {1}", new Object[]{wbd, webModule.getName()});
if(wbd == null) {
// for some system app like adminGUI, wbd is null
return true;
}
final Application application = wbd.getApplication();
// unload PUs only for standaalone wars.
// embedded wars are taken care of in ApplicationLoader.
if(application != null && application.isVirtual()) {
try{
new PersistenceUnitLoaderImpl().unload(new ApplicationInfoImpl(
explodedLocation, wbd, webModule));
} catch(Exception e){
_logger.log(Level.WARNING, e.getMessage(), e);
return false;
}
}
return true;
|
|