URL warUrl = new URL(warUrlStr);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
metaData.setContextLoader(loader);
StandardContext context = (StandardContext)Class.forName(config.getContextClassName()).newInstance();
DeploymentUnit depUnit = webApp.getDeploymentUnit();
TomcatInjectionContainer injectionContainer = new TomcatInjectionContainer(webApp, depUnit, context, getPersistenceUnitDependencyResolver());
Loader webLoader = depUnit.getAttachment(Loader.class);
if (webLoader == null)
webLoader = getWebLoader(depUnit, metaData, loader, warUrl, injectionContainer);
webApp.setName(warUrl.getPath());
webApp.setClassLoader(loader);
webApp.setURL(warUrl);
String objectNameS = config.getCatalinaDomain() + ":j2eeType=WebModule,name=//" + ((hostName == null) ? "localhost" : hostName) + ctxPath
+ ",J2EEApplication=none,J2EEServer=none";
ObjectName objectName = new ObjectName(objectNameS);
if (Registry.getRegistry(null, null).getMBeanServer().isRegistered(objectName))
throw new DeploymentException("Web mapping already exists for deployment URL " + warUrlStr);
Registry.getRegistry(null, null).registerComponent(context, objectName, config.getContextClassName());
context.setConfigFile(CONTEXT_CONFIG_FILE);
context.setInstanceManager(injectionContainer);
context.setDefaultContextXml("context.xml");
context.setDefaultWebXml("conf/web.xml");
context.setPublicId(metaData.getPublicID());
String docBase = depUnit.getAttachment("org.jboss.web.explicitDocBase", String.class);
if (docBase == null)
docBase = warUrl.getFile();
context.setDocBase(docBase);
// If there is an alt-dd set it
if (metaData.getAlternativeDD() != null)
{
log.debug("Setting altDDName to: " + metaData.getAlternativeDD());
context.setAltDDName(metaData.getAlternativeDD());
}
context.setJavaVMs(javaVMs);
context.setServer(serverName);
context.setSaveConfig(false);
if (webLoader != null)
{
context.setLoader(webLoader);
}
else
{
context.setParentClassLoader(loader);
}
context.setDelegate(webApp.getJava2ClassLoadingCompliance());
// Javac compatibility whenever possible
String[] jspCP = getCompileClasspath(loader);
StringBuffer classpath = new StringBuffer();
for (int u = 0; u < jspCP.length; u++)
{
String repository = jspCP[u];
if (repository == null)
continue;
if (repository.startsWith("file://"))
repository = repository.substring(7);
else if (repository.startsWith("file:"))
repository = repository.substring(5);
else
continue;
if (repository == null)
continue;
// ok it is a file. Make sure that is is a directory or jar file
File fp = new File(repository);
if (!fp.isDirectory())
{
// if it is not a directory, try to open it as a zipfile.
try
{
// avoid opening .xml files
if (fp.getName().toLowerCase().endsWith(".xml"))
continue;
ZipFile zip = new ZipFile(fp);
zip.close();
}
catch (IOException e)
{
continue;
}
}
if (u > 0)
classpath.append(File.pathSeparator);
classpath.append(repository);
}
context.setCompilerClasspath(classpath.toString());
// Set the session cookies flag according to metadata
switch (metaData.getSessionCookies())
{
case JBossWebMetaData.SESSION_COOKIES_ENABLED:
context.setCookies(true);
log.debug("Enabling session cookies");
break;
case JBossWebMetaData.SESSION_COOKIES_DISABLED:
context.setCookies(false);
log.debug("Disabling session cookies");
break;
default:
log.debug("Using session cookies default setting");
}
String metaDataSecurityDomain = metaData.getSecurityDomain();
if (metaDataSecurityDomain != null)
metaDataSecurityDomain = metaDataSecurityDomain.trim();
// Add a valve to establish security context
SecurityContextEstablishmentValve scevalve = new SecurityContextEstablishmentValve(metaDataSecurityDomain, SecurityUtil.unprefixSecurityDomain(config
.getDefaultSecurityDomain()), SecurityActions.loadClass(config.getSecurityContextClassName()), getSecurityManagement());
context.addValve(scevalve);
// Add a valve to estalish the JACC context before authorization valves
Certificate[] certs = null;
CodeSource cs = new CodeSource(warUrl, certs);
JaccContextValve jaccValve = new JaccContextValve(metaData, cs);
context.addValve(jaccValve);
// Set listener
context.setConfigClass("org.jboss.web.tomcat.service.deployers.JBossContextConfig");
context.addLifecycleListener(new EncListener(loader, webLoader, injectionContainer, webApp));
// Pass the metadata to the RunAsListener via a thread local
RunAsListener.metaDataLocal.set(metaData);
JBossContextConfig.metaDataLocal.set(metaData);
JBossContextConfig.metaDataShared.set(config.getSharedMetaData());
JBossContextConfig.deployerConfig.set(config);
JBossContextConfig.kernelLocal.set(kernel);
JBossContextConfig.deploymentUnitLocal.set(unit);
try
{
// Start it
context.start();
// Build the ENC
}
catch (Exception e)
{
context.destroy();
DeploymentException.rethrowAsDeploymentException("URL " + warUrlStr + " deployment failed", e);
}
finally
{
RunAsListener.metaDataLocal.set(null);
JBossContextConfig.metaDataLocal.set(null);
JBossContextConfig.metaDataShared.set(null);
JBossContextConfig.deployerConfig.set(null);
JBossContextConfig.kernelLocal.set(null);
JBossContextConfig.deploymentUnitLocal.set(null);
}
if (context.getState() != 1)
{
context.destroy();
throw new DeploymentException("URL " + warUrlStr + " deployment failed");
}
// Clustering
if (metaData.getDistributable() != null)