User: roberto
Date: 00/12/02 16:19:46
Modified: tomcat/src/main/org/jboss/tomcat EmbeddedTomcatService.java
Log:
support for contexts as specified in tomcat�s config file
Revision Changes Path
1.6 +62 -5
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatService.java
Index: EmbeddedTomcatService.java
===================================================================
RCS file:
/products/cvs/ejboss/contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatService.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EmbeddedTomcatService.java 2000/11/16 01:31:32 1.5
+++ EmbeddedTomcatService.java 2000/12/03 00:19:46 1.6
@@ -8,12 +8,16 @@
package org.jboss.tomcat;
+//import java.io.IOException;
import java.io.File;
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;
@@ -38,6 +42,18 @@
import org.apache.tomcat.request.Jdk12Interceptor;
import org.apache.tomcat.session.StandardSessionInterceptor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+
+
+
+
/**
* A service to launch tomcat from JMX.
*
@@ -50,7 +66,7 @@
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin Lewis</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class EmbeddedTomcatService extends ServiceMBeanSupport
implements EmbeddedTomcatServiceMBean, MBeanRegistration {
@@ -69,6 +85,10 @@
// the port tomcat must listen to
int port;
+ // the config file to be used
+
+ String configFile;
+
// repository for deployed URLs and the associated servletContexts
Hashtable deployedURLs = new Hashtable();
@@ -77,11 +97,12 @@
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- public EmbeddedTomcatService(int port) {
+
+ public EmbeddedTomcatService(String configFile, int port) {
+ this.configFile = configFile;
this.port = port;
}
-
-
+
// Public --------------------------------------------------------
public ObjectName getObjectName(MBeanServer server, ObjectName name)
throws javax.management.MalformedObjectNameException {
@@ -146,7 +167,43 @@
// add root context
deploy("/", "file:" + tomcatHome + "/webapps/ROOT");
-
+
+ // add contexts from file
+
+ // Create an instance of the DocumentBuilderFactory
+ DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
+
+ //Get the DocumentBuilder from the factory that we just got above.
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+
+ // parse the config file
+ // ROB: it�s not bulletproof maybe should validate against a dtd file
+ Document doc = docBuilder.parse(new File(configFile));
+
+ // get list with contexts
+ NodeList contexts = doc.getElementsByTagName("Context");
+
+
+ // add them
+ for(int i=0; i<contexts.getLength(); i++) {
+ Element context = (Element)contexts.item(i);
+ String path = context.getAttribute("path");
+ String docBase = context.getAttribute("docBase");
+ File f = new File(docBase);
+ // check if docbase is of type /something in which case add tomcat home
+ if(!f.exists()) {
+ deploy(path, "file:" + tomcatHome + "/" + docBase);
+ //System.out.println("file:" + tomcatHome + "/" + docBase);
+ }
+
+ // otherwise if it�s c:/something do nothing
+ else {
+ deploy(path, "file:" + docBase);
+ //System.out.println("file:" + docBase);
+ }
+ }
+
+
// add endpoint (web service)
embededTomcat.addEndpoint(port, null, null);