User: starksm
Date: 01/05/23 11:26:33
Added: tomcat/src/main/org/jboss/tomcat
EmbeddedTomcatServiceSX.java
EmbeddedTomcatServiceSXMBean.java
Log:
Update the AbstractWebContainer based service to work when web components
are deployed on startup of the web application.
Revision Changes Path
1.1
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatServiceSX.java
Index: EmbeddedTomcatServiceSX.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.tomcat;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.File;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.InetAddress;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.management.*;
import javax.servlet.ServletContext;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.jboss.ejb.DeploymentException;
import org.jboss.logging.log4j.CategoryStream;
import org.jboss.web.AbstractWebContainer;
import org.jboss.web.AbstractWebContainer.WebDescriptorParser;
import org.jboss.web.WebApplication;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.tomcat.core.Context;
import org.apache.tomcat.core.ContextManager;
import org.apache.tomcat.logging.Logger;
/** An implementation of the AbstractWebContainer for the Jakarta Tomcat
3.2.1 servlet container. This uses the TomcatEntry instance to parse the
standard conv/server.xml config file as does the EmbeddedTomcatService.
@see org.jboss.web.AbstractWebContainer
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class EmbeddedTomcatServiceSX extends AbstractWebContainer
implements EmbeddedTomcatServiceSXMBean
{
// Constants -----------------------------------------------------
public static final String NAME = "EmbeddedTomcatSX";
private Category category;
private TomcatEntry tomcat = null;
private String configFile = null;
public String getName()
{
return NAME;
}
public String getConfigFile()
{
return configFile;
}
public void setConfigFile(String configFile)
{
this.configFile = configFile;
}
public void startService() throws Exception
{
String baseName = AbstractWebContainer.category.getName();
category = Category.getInstance(baseName+"."+NAME);
category.info("Starting " + NAME + "....");
// Redirect the default logging to log4j
PrintWriter writer = new PrintWriter(new CategoryStream(category,
Priority.DEBUG, System.out));
Logger.setDefaultSink(writer);
String[] args = {};
if( configFile != null )
{
args = new String[]{"", configFile};
}
tomcat = new TomcatEntry(args);
category.info("OK");
}
public void stopService()
{
if( tomcat != null )
{
try
{
tomcat.stopTomcat();
}
catch(Exception e)
{
}
}
}
/** Perform the tomcat specific deployment steps.
*/
protected WebApplication performDeploy(String ctxPath, String warUrl,
WebDescriptorParser webAppParser) throws Exception
{
category.info("deploy, ctxPath="+ctxPath+", warUrl="+warUrl);
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
// Create the container context in tomcat
Context ctx = tomcat.addRawContext(ctxPath, new URL(warUrl));
ctx.setAttribute("org.jboss.web.AbstractWebContainer.WebDescriptorParser",
webAppParser);
/* Set the parent class loader of the context to the current thread
so that servlet/jsp to ejb calls within this vm bypass serialization
when the ejb container is optimized.
*/
ContextManager contextManager = ctx.getContextManager();
contextManager.setParentClassLoader(ctxClassLoader);
// Make the servlet context available
ServletContext servletCtx = ctx.getFacade();
// Now initialize the web app context
tomcat.initContext(servletCtx);
/* Would like to add JBoss realm request interceptor as the next to last
interceptor but the ContextManager interface does not allow this
as of tomcat 3.2.1...
*/
// Get the servlet class loader
ClassLoader scl = (ClassLoader) ctx.getServletLoader().getClassLoader();
// Get the web-app.xml and jboss-web.xml deployment descriptors
File webXml = contextManager.getAbsolute(new File(ctx.getDocBase() +
"/WEB-INF/web.xml"));
File jbossWebXml = contextManager.getAbsolute(new File(ctx.getDocBase() +
"/WEB-INF/jboss-web.xml"));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document webDoc = parser.parse(webXml);
Element web = webDoc.getDocumentElement();
Element jbossWeb = null;
if( jbossWebXml.exists() == true )
{
Document jbossWebDoc = parser.parse(jbossWebXml);
jbossWeb = jbossWebDoc.getDocumentElement();
}
URL url = new URL(warUrl);
WebApplication appInfo = new WebApplication(url.getFile(), url, scl);
appInfo.setWebApp(web);
appInfo.setJbossWeb(jbossWeb);
appInfo.setAppData(servletCtx);
category.debug("Initialized: "+appInfo);
return appInfo;
}
/** Perform the tomcat specific deployment steps.
*/
public void performUndeploy(String warUrl) throws Exception
{
// find the javax.servlet.ServletContext in the repository
WebApplication appInfo = getDeployedApp(warUrl);
ServletContext servletCtx = (ServletContext) appInfo.getAppData();
if(servletCtx == null)
throw new DeploymentException("URL " + warUrl + " is not deployed");
tomcat.removeContext(servletCtx);
}
}
1.1
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatServiceSXMBean.java
Index: EmbeddedTomcatServiceSXMBean.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.tomcat;
import org.jboss.ejb.DeploymentException;
import org.jboss.web.AbstractWebContainerMBean;
/**
* Management interface for the Embedded Tomcat service
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
* @author [EMAIL PROTECTED]
* @version $Revision: 1.1 $
*/
public interface EmbeddedTomcatServiceSXMBean extends AbstractWebContainerMBean
{
/** Get the tomcat xml configuration file path */
public String getConfigFile();
/** Set the tomcat xml configuration file path */
public void setConfigFile(String configFile);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development