protected void performDeploy(WebApplication appInfo,
String warUrl,
AbstractWebContainer.WebDescriptorParser webAppParser) throws Exception {
WebMetaData metaData = appInfo.getMetaData();
String ctxPath = metaData.getContextRoot();
if (ctxPath.equals("/") || ctxPath.equals("/ROOT"))
{
log.info("deploy root context=" + ctxPath);
ctxPath = "";
metaData.setContextRoot(ctxPath);
}
log.info("deploy, ctxPath=" + ctxPath + ", warUrl=" + warUrl);
URL url = new URL(warUrl);
// Servlet engines needs a war in a dir so extract the nested war
if (url.getProtocol().equals("njar"))
{
url = org.jboss.net.protocol.njar.Handler.njarToFile(url);
log.debug("Extracted war from njar, warUrl=" + url);
File warFile = new File(url.getFile());
String warFileName = warFile.getName();
warFileName = warFileName.substring(0, warFileName.length() - 3);
warFileName += "war";
File warDir = new File(warFile.getParent(), warFileName);
FileInputStream warStream = new FileInputStream(warFile);
JarUtils.unjar(warStream, warDir);
warStream.close();
log.debug("Unpacked war into dir: " + warDir);
url = warDir.toURL();
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
appInfo.setName(url.getPath());
appInfo.setClassLoader(loader);
appInfo.setURL(url);
String hostName = metaData.getVirtualHost();
if (ctxPath.equals(""))
ctxPath = "/";
if (ctxPath.equals("/ROOT"))
ctxPath = "/";
// XXX How do I find the j2eeApp name ???
// XXX How can I find the jboss "id" if any ??
String objectNameS = catalinaDomain + ":j2eeType=WebModule,name=//" +
((hostName == null) ? "localhost" : hostName) + ctxPath +
",j2eeApp=none,j2eeServer=jboss";
ObjectName objectName = new ObjectName(objectNameS);
if (server.isRegistered(objectName))
{
// workaround
server.invoke(objectName, "destroy", new Object[]{},
new String[]{});
log.info("Already exists, unregistering " + objectName);
server.unregisterMBean(objectName);
}
server.createMBean("org.apache.commons.modeler.BaseModelMBean",
objectName, new Object[]{contextClassName},
new String[]{"java.lang.String"});
server.setAttribute(objectName, new Attribute
("docBase", url.getFile()));
server.setAttribute(objectName, new Attribute
("defaultWebXml", "web.xml"));
if (useJBossWebLoader) {
WebCtxLoader webLoader = new WebCtxLoader(loader);
webLoader.setWarURL(url);
server.setAttribute(objectName, new Attribute
("loader", webLoader));
} else {
server.setAttribute(objectName, new Attribute
("parentClassLoader", loader));
}
server.setAttribute(objectName, new Attribute
("delegate", new Boolean (getJava2ClassLoadingCompliance())));
String[] jspCP = getCompileClasspath(loader);
StringBuffer classpath = new StringBuffer();
for (int u = 0; u < jspCP.length; u++)
{
String repository = jspCP[u];
if (repository.startsWith("file://"))
repository = repository.substring(7);
else if (repository.startsWith("file:"))
repository = repository.substring(5);
else
continue;
if (repository == null)
continue;
if (u > 0)
classpath.append(File.pathSeparator);
classpath.append(repository);
}
server.setAttribute(objectName, new Attribute
("compilerClasspath", classpath.toString()));
// We need to establish the JNDI ENC prior to the start
// of the web container so that init on startup servlets are able
// to interact with their ENC. We hook into the context lifecycle
// events to be notified of the start of the
// context as this occurs before the servlets are started.
webAppParser.parseWebAppDescriptors(loader, appInfo.getMetaData());
server.invoke(objectName, "init", new Object[]{}, new String[]{});
//server.invoke( objectName, "start", new Object[]{}, new String[] {});
appInfo.setAppData(objectName);
ObjectName queryObjectName = new ObjectName
(catalinaDomain + ":host="
+ ((hostName == null) ? "localhost" : hostName)
+ ",path=" + ctxPath + ",type=Valve,*");
Iterator iterator =
server.queryMBeans(queryObjectName, null).iterator();
while (iterator.hasNext())
{
ObjectName valveObjectName =
((ObjectInstance) iterator.next()).getObjectName();
String name = valveObjectName.getKeyProperty("name");
if ((name != null) && (name.indexOf("Authenticator") >= 0))
{
log.info("Set auth base caching off on " + valveObjectName);
server.setAttribute(valveObjectName, new Attribute
("cache", Boolean.FALSE));
}
}
log.debug("Initialized: " + appInfo + " " + objectName);
}
Perform the tomcat specific deployment steps. |