dain 2003/11/16 14:36:31
Modified: modules/web/src/java/org/apache/geronimo/web
AbstractWebContainer.java WebApplication.java
modules/web/src/java/org/apache/geronimo/web/jetty
JettyWebApplication.java
Log:
Added loading of JNDI context... still needs work
Revision Changes Path
1.16 +117 -218
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebContainer.java
Index: AbstractWebContainer.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebContainer.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AbstractWebContainer.java 16 Nov 2003 02:25:36 -0000 1.15
+++ AbstractWebContainer.java 16 Nov 2003 22:36:31 -0000 1.16
@@ -56,11 +56,9 @@
package org.apache.geronimo.web;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
@@ -79,26 +77,39 @@
import javax.management.Notification;
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import javax.transaction.UserTransaction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.service.AbstractManagedContainer;
import org.apache.geronimo.core.service.Component;
-import org.apache.geronimo.core.service.Container;
+import
org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
import org.apache.geronimo.kernel.deployment.DeploymentException;
+import org.apache.geronimo.kernel.deployment.DeploymentHelper;
+import org.apache.geronimo.kernel.deployment.DeploymentInfo;
import org.apache.geronimo.kernel.deployment.DeploymentPlan;
import org.apache.geronimo.kernel.deployment.goal.DeployURL;
import org.apache.geronimo.kernel.deployment.goal.RedeployURL;
import org.apache.geronimo.kernel.deployment.goal.UndeployURL;
-import org.apache.geronimo.kernel.deployment.scanner.URLType;
+import org.apache.geronimo.kernel.deployment.service.ClassSpaceMetadata;
import org.apache.geronimo.kernel.deployment.service.MBeanMetadata;
+import org.apache.geronimo.kernel.deployment.task.CreateClassSpace;
import org.apache.geronimo.kernel.deployment.task.DestroyMBeanInstance;
import org.apache.geronimo.kernel.deployment.task.RegisterMBeanInstance;
import org.apache.geronimo.kernel.deployment.task.StartMBeanInstance;
import org.apache.geronimo.kernel.deployment.task.StopMBeanInstance;
+import org.apache.geronimo.kernel.jmx.JMXKernel;
import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.naming.java.ComponentContextBuilder;
+import org.apache.geronimo.naming.java.ReadOnlyContext;
+import org.apache.geronimo.naming.java.ReferenceFactory;
+import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
import org.apache.geronimo.web.deploy.RemoveWebApplication;
+import org.apache.geronimo.xml.deployment.GeronimoWebAppLoader;
+import org.apache.geronimo.xml.deployment.LoaderUtil;
+
import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
/**
* AbstractWebContainer
@@ -121,8 +132,8 @@
public abstract class AbstractWebContainer
extends AbstractManagedContainer
implements WebContainer, AbstractWebContainerMBean,
MBeanRegistration {
- private final static Log log =
- LogFactory.getLog(AbstractWebContainer.class);
+
+ private final static Log log =
LogFactory.getLog(AbstractWebContainer.class);
/**
* Location of the default web.xml file
@@ -139,19 +150,17 @@
- /*
--------------------------------------------------------------------------------------
*/
- /**Constructor
+ /**
+ * Constructor
*/
public AbstractWebContainer() {
}
- /*
--------------------------------------------------------------------------------------
*/
- /**Monitor JMX notifications
+ /**
+ * Monitor JMX notifications
* When a web layer object such as a WebConnector, a WebAccessLog
* or a WebApplication is registered in JMX, then set up the containment
* relationship with it so that it becomes one of our components.
- * @param n a <code>Notification</code> value
- * @param o an <code>Object</code> value
*/
public void handleNotification(Notification n, Object o) {
ObjectName source = null;
@@ -166,13 +175,13 @@
source = notification.getMBeanName();
if (server.isInstanceOf(source,
WebConnector.class.getName())) {
log.debug("Received registration notification for
webconnecter=" + source);
- server.setAttribute(source, new Attribute("Container",
(Container) this));
+ server.setAttribute(source, new Attribute("Container",
this));
} else if (server.isInstanceOf(source,
WebAccessLog.class.getName())) {
log.debug("Received registration notification for
weblog=" + source);
- server.setAttribute(source, new Attribute("Container",
(Container) this));
+ server.setAttribute(source, new Attribute("Container",
this));
} else if (server.isInstanceOf(source,
WebApplication.class.getName())) {
log.debug("Received registration notification for
webapplication=" + source);
- server.setAttribute(source, new Attribute("Container",
(Container) this));
+ server.setAttribute(source, new Attribute("Container",
this));
} else
log.debug("Ignoring registration of mbean=" + source);
}
@@ -189,133 +198,65 @@
super.handleNotification(n, o);
}
-
-
- /*
--------------------------------------------------------------------------------------
*/
- /**Something to be deployed.
+ /**
+ * Something to be deployed.
* We will deploy it if it looks and smells like a webapp. That is, it
* is either a packed war with a ".war" suffix or a directory, and
* in either case contains a WEB-INF/web.xml file.
- *
- * @param goal a <code>DeployURL</code> value
- * @param goals a <code>Set</code> value
- * @param plans a <code>Set</code> value
- * @return a <code>boolean</code> value
- * @exception DeploymentException if an error occurs
- *
* @jmx.managed-operation
*/
- public boolean deploy(DeployURL goal, Set goals, Set plans)
- throws DeploymentException {
-
+ public boolean deploy(DeployURL goal, Set goals, Set plans) throws
DeploymentException {
if (getStateInstance() != State.RUNNING)
throw new DeploymentException("WebContainer " + getObjectName()
+ " cannot deploy as it is not RUNNING");
- InputStream is;
URL url = goal.getUrl();
- URI baseURI = URI.create(url.toString()).normalize();
- URLType type = goal.getType();
- URL webXmlURL = null;
+ DeploymentHelper deploymentHelper = new DeploymentHelper(url,
goal.getType(), "WebApplication", ".war", "web.xml", "geronimo-web.xml");
+ URL geronimoURL = deploymentHelper.locateGeronimoDD();
- //check if this is a deployable webapp. This is either a directory
or a war file that contains a WEB-INF directory
- if (type == URLType.PACKED_ARCHIVE) {
- InputStream stream = null;
- try {
- URL webInfURL =
- new URL("jar:" + url.toExternalForm() +
"!/WEB-INF/web.xml");
- stream = webInfURL.openStream();
- } catch (FileNotFoundException e) {
- return false;
- } catch (IOException e) {
- throw new DeploymentException("Failed to open stream for
URL: " + url, e);
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException iox) {
- throw new DeploymentException("Failed to close stream
for URL: " + url, iox);
- }
- }
- } else if (type == URLType.UNPACKED_ARCHIVE) {
- // check if there is a WEB-INF
- InputStream stream = null;
- try {
- URL webInfURL = new URL(url, "WEB-INF/web.xml");
- stream = webInfURL.openStream();
- } catch (FileNotFoundException e) {
- return false;
- } catch (IOException e) {
- throw new DeploymentException("Failed to open stream for
URL: " + url, e);
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException iox) {
- throw new DeploymentException("Failed to close stream
for URL: " + url, iox);
- }
- }
- } else if (type == URLType.RESOURCE) {
- //we will try and deploy a WEB-INF/web.xml by looking for the
parent directory
- if (!url.getPath().endsWith("web.xml"))
- return false;
-
- try {
- File file = new File(url.toExternalForm());
-
- if (!file.exists())
- throw new DeploymentException("No such file:" + url);
-
- File parent = file.getParentFile();
- if (!parent.getName().equals("WEB-INF"))
- throw new DeploymentException("web.xml must be in
WEB-INF directory");
-
- // find the parent dir of WEB-INF and try to deploy that
- parent = parent.getParentFile();
- url = parent.toURL();
- } catch (NullPointerException e) {
- throw new DeploymentException("No path to web.xml file", e);
- } catch (MalformedURLException e) {
- throw new DeploymentException("Bad url for possible webapp
directory", e);
- }
-
- } else {
- //we can't deploy any other structure
+ // Is the specific URL deployable?
+ if (null == geronimoURL) {
+ log.info("Looking at and rejecting url " + url);
return false;
}
+ URI baseURI = URI.create(url.toString()).normalize();
- log.debug("Identified webapp to deploy");
+ log.trace("Planning the ejb module deployment " + url);
- //check to see if there is already a deployment for the webapp
- ObjectName deploymentName = null;
- try {
- deploymentName =
- new
ObjectName("geronimo.deployment:role=DeploymentUnit,url="
- + ObjectName.quote(url.toString())
- + ",type=WebApplication");
- } catch (MalformedObjectNameException e) {
- throw new DeploymentException(e);
- }
+ // One can deploy the specified URL. One removes it from the current
goal set.
+ goals.remove(goal);
- if (server.isRegistered(deploymentName))
- throw new DeploymentException("A web application deployment is
already registered at:"
- + deploymentName.toString());
-
- //Deploy the deployment unit itself. This registers an mbean for the
deployment unit,
- //so we wind up with an mbean for the deployment of the webapp, as
well as one for
- //the webapp itself.
- DeploymentPlan deploymentUnitPlan = new DeploymentPlan();
- WebDeployment deploymentInfo =
- new WebDeployment(deploymentName, null, url);
- deploymentUnitPlan.addTask(
- new RegisterMBeanInstance(server, deploymentName,
deploymentInfo));
- MBeanMetadata deploymentUnitMetadata =
- new MBeanMetadata(deploymentName);
- deploymentUnitPlan.addTask(
- new StartMBeanInstance(server, deploymentUnitMetadata));
- plans.add(deploymentUnitPlan);
+ ObjectName deploymentUnitName =
deploymentHelper.buildDeploymentName();
+ // Add a task to deploy and start the deployment unit mbean
+ DeploymentPlan deploymentInfoPlan = new DeploymentPlan();
+ DeploymentInfo deploymentInfo = new
DeploymentInfo(deploymentUnitName, null, url);
+ deploymentInfoPlan.addTask(new RegisterMBeanInstance(server,
deploymentUnitName, deploymentInfo));
+ MBeanMetadata deploymentUnitMetadata = new
MBeanMetadata(deploymentUnitName);
+ deploymentInfoPlan.addTask(new StartMBeanInstance(server,
deploymentUnitMetadata));
+
+ // Define the ClassSpace for the archives.
+ ClassSpaceMetadata classSpaceMetaData =
deploymentHelper.buildClassSpace();
+ // @todo we need to be in the ear's classspace
+ deploymentInfoPlan.addTask(new CreateClassSpace(server,
classSpaceMetaData));
+ plans.add(deploymentInfoPlan);
+
+ // Load the deployment descriptor into our POJO
+ URI geronimoWebURI = URI.create(geronimoURL.toString()).normalize();
+ log.trace("Loading deployment descriptor " + geronimoWebURI);
+
+ GeronimoWebAppDocument geronimoWebAppDoc = null;
+ try {
+ Document document = LoaderUtil.parseXML(new
InputStreamReader(geronimoURL.openStream()));
+ geronimoWebAppDoc = GeronimoWebAppLoader.load(document);
+ } catch (FileNotFoundException e) {
+ throw new DeploymentException("Deployment descriptor not found",
e);
+ } catch (SAXException e) {
+ throw new DeploymentException("geronimo-web.xml malformed", e);
+ } catch (IOException e) {
+ throw new DeploymentException("Deployment descriptor not
readable", e);
+ }
- //Create a webapp typed to the concrete type of the web container
+ // Create a webapp typed to the concrete type of the web container
WebApplication webapp = createWebApplication(baseURI);
ObjectName webappName;
try {
@@ -328,35 +269,33 @@
DeploymentPlan webappPlan = new DeploymentPlan();
webappPlan.addTask(new RegisterMBeanInstance(server, webappName,
webapp));
- //Set up a start dependency between the webapp and the deployment
unit as a whole.
- //Thus, when the deployer starts the deployment, the webapp itself
will be started. This
- //works better for the ServiceDeploymentPlanner, where one
deployment unit can contain
- //many services to be deployed, but the Scanner is only ever going
to give us individual
- //webapps
+ // Set up a start dependency between the webapp and the deployment
unit as a whole.
+ // Thus, when the deployer starts the deployment, the webapp itself
will be started. This
+ // works better for the ServiceDeploymentPlanner, where one
deployment unit can contain
+ // many services to be deployed, but the Scanner is only ever going
to give us individual
+ // webapps
MBeanMetadata webappMetadata = new MBeanMetadata(webappName);
- webappMetadata.setParentName(deploymentName);
- dependencyService.addStartDependency(webappName, deploymentName);
-
- // crack open the war and read the web.xml and geronimo-web.xml into
the POJOs
- //TODO
+ webappMetadata.setParentName(deploymentUnitName);
+ dependencyService.addStartDependency(webappName, deploymentUnitName);
- //Set up the ContextPath, which can come from:
+ // Set up the ContextPath, which can come from:
// application.xml
// geronimo-web.xml
// name of the war (without .war extension) or webapp dir
//
- //As we don't have any ear deployers (yet), so therefore no
application.xml files,
- //nor any geronimo-web.xml files, then we will only support using
the name of the
- //webapp.
+ // As we don't have any ear deployers (yet), so therefore no
application.xml files,
+ // nor any geronimo-web.xml files, then we will only support using
the name of the
+ // webapp.
webapp.setContextPath(extractContextPath(baseURI));
// Set up the parent classloader for the webapp
+ // @todo we need to be in the ear's classspace
webapp.setParentClassLoader(getClass().getClassLoader());
- //Set up the ENC etc
- //TODO
+ // Set up the ENC etc
+
webapp.setComponentContext(this.getComponentContext(geronimoWebAppDoc, null));
- //Add a task to start the webapp which will finish configuring it
+ // Add a task to start the webapp which will finish configuring it
webappPlan.addTask(new StartMBeanInstance(server, webappMetadata));
plans.add(webappPlan);
@@ -364,15 +303,15 @@
return true;
}
+ private ReadOnlyContext getComponentContext(GeronimoWebAppDocument
geronimoWebAppDoc, UserTransaction userTransaction) throws DeploymentException {
+ ReferenceFactory referenceFactory = new
JMXReferenceFactory(JMXKernel.getMBeanServerId(server));
+ ComponentContextBuilder builder = new
ComponentContextBuilder(referenceFactory, userTransaction);
+ ReadOnlyContext context =
builder.buildContext(geronimoWebAppDoc.getWebApp());
+ return context;
+ }
- /*
--------------------------------------------------------------------------------------
*/
- /**Remove the deployment of a webapp.
- *
- * @param goal
- * @param goals
- * @param plans
- * @return
- * @throws DeploymentException
+ /**
+ * Remove the deployment of a webapp.
*
* @jmx.managed-operation
*/
@@ -469,51 +408,36 @@
return true;
}
-
-
-
- /*
--------------------------------------------------------------------------------------
*/
- /**Handle a redeployment.
+ /**
+ * Handle a redeployment.
*
* This is going to be tricky, as I believe the Scanner just always
* inserts a redeploy goal if it scans the directory and finds the same
* url as was there previously - I don't think it is checking the
timestamps.
- * @param goal
- * @param goals
- * @return
- * @throws DeploymentException
- *
* @jmx.managed-operation
*/
- public boolean redeploy(RedeployURL goal, Set goals)
- throws DeploymentException {
+ public boolean redeploy(RedeployURL goal, Set goals) throws
DeploymentException {
//TODO
goals.remove(goal);
return true;
}
-
- /*
--------------------------------------------------------------------------------------
*/
- /**Create a WebApplication suitable to the container's type.
+ /**
+ * Create a WebApplication suitable to the container's type.
* @return WebApplication instance, preferably derived from
AbstractWebApplication suitable to the container
*/
public abstract WebApplication createWebApplication(URI baseURI);
-
-
-
- /*
--------------------------------------------------------------------------------------
*/
- /**Get the URI of the web defaults.
+ /**
+ * Get the URI of the web defaults.
* @return the location of the default web.xml file for this container
*/
public URI getDefaultWebXmlURI() {
return defaultWebXmlURI;
}
-
-
- /*
--------------------------------------------------------------------------------------
*/
- /** Set a uri of a web.xml containing defaults for this container.
+ /**
+ * Set a uri of a web.xml containing defaults for this container.
* @param uri the location of the default web.xml file
*/
public void setDefaultWebXmlURI(URI uri) {
@@ -521,56 +445,48 @@
defaultWebXmlURI = uri;
}
-
- /*
--------------------------------------------------------------------------------------
*/
- /** Get the parsed web defaults
- *
- * @return
+ /**
+ * Get the parsed web defaults
+ * @return the default web xml document
*/
public Document getDefaultWebXmlDoc() {
return defaultWebXmlDoc;
}
-
-
- /*
--------------------------------------------------------------------------------------
*/
/**
* Get a webapp context path from its uri
- *
- * @param uri an <code>URI</code> value
- * @return a <code>String</code> value
*/
- public String extractContextPath(URI uri) {
+ protected String extractContextPath(URI uri) {
String path = uri.getPath();
- if (path.endsWith("/"))
+ if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
+ }
int sepIndex = path.lastIndexOf('/');
- if (sepIndex > 0)
+ if (sepIndex > 0) {
path = path.substring(sepIndex + 1);
+ }
- if (path.endsWith(".war"))
+ if (path.endsWith(".war")) {
path = path.substring(0, path.length() - 4);
+ }
return "/" + path;
}
-
- /*
--------------------------------------------------------------------------------------
*/
/**
* Parse the web defaults descriptor
* @throws Exception
*/
protected void parseWebDefaults() throws Exception {
- if (defaultWebXmlURI == null)
+ if (defaultWebXmlURI == null) {
return;
+ }
- //TODO
+ // TODO
}
-
- /*
--------------------------------------------------------------------------------------
*/
/**
* Add a component to this container's containment hierarchy
* @see
org.apache.geronimo.core.service.Container#addComponent(org.apache.geronimo.core.service.Component)
@@ -587,9 +503,8 @@
}
}
- /*
--------------------------------------------------------------------------------------
*/
/**
- * Remove a component from this container's hierarchy
+ * Remove a component from this container's hierarchy
* @see
org.apache.geronimo.core.service.Container#removeComponent(org.apache.geronimo.core.service.Component)
*/
public void removeComponent(Component component) {
@@ -602,53 +517,37 @@
super.removeComponent(component);
}
-
- /*
--------------------------------------------------------------------------------------
*/
/**
* Method called by addComponent after a WebConnector has been added.
- * @param connector
*/
protected void webConnectorAdded(WebConnector connector) {
-
}
- /*
--------------------------------------------------------------------------------------
*/
/**
* Method called by addComponment after a WebApplication has been added.
- * @param app
*/
protected void webApplicationAdded(WebApplication app) {
- webAppMap.put(((AbstractWebApplication) app).getObjectName(), app);
+ webAppMap.put(app.getObjectName(), app);
}
- /*
--------------------------------------------------------------------------------------
*/
- /**
- * @param log
- */
protected void webAccessLogAdded(WebAccessLog log) {
}
- /*
--------------------------------------------------------------------------------------
*/
/**
* Method called by removeComponent before a WebConnector has been
removed.
- * @param connector
*/
protected void webConnectorRemoval(WebConnector connector) {
}
- /*
--------------------------------------------------------------------------------------
*/
/**
* Method called by removeComponment before a WebApplication has been
removed.
- * @param app
*/
protected void webApplicationRemoval(WebApplication app) {
- webAppMap.remove(((AbstractWebApplication) app).getObjectName());
+ webAppMap.remove(app.getObjectName());
}
- /*
--------------------------------------------------------------------------------------
*/
/**
* Remove an access log service from the container
- * @param log
*/
protected void webAccessLogRemoval(WebAccessLog log) {
}
1.12 +3 -3
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebApplication.java
Index: WebApplication.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebApplication.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WebApplication.java 16 Nov 2003 07:18:26 -0000 1.11
+++ WebApplication.java 16 Nov 2003 22:36:31 -0000 1.12
@@ -123,11 +123,11 @@
* Gets the JNDI context for the web application.
* @return the jndi context
*/
- public ReadOnlyContext getContext();
+ public ReadOnlyContext getComponentContext();
/**
* Sets the JNDI context for the web application.
* @param context the jndi context
*/
- public void setContext(ReadOnlyContext context);
+ public void setComponentContext(ReadOnlyContext context);
}
1.5 +6 -7
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java
Index: JettyWebApplication.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JettyWebApplication.java 16 Nov 2003 07:18:26 -0000 1.4
+++ JettyWebApplication.java 16 Nov 2003 22:36:31 -0000 1.5
@@ -23,8 +23,7 @@
* @version $Revision$ $Date$
*/
public class JettyWebApplication extends AbstractWebApplication implements
JettyWebApplicationMBean {
- private WebApplicationContext jettyContext;
- private ReadOnlyContext context;
+ private JettyWebApplicationContext jettyContext;
private final Log log = LogFactory.getLog(getClass());
public JettyWebApplication() {
@@ -86,12 +85,12 @@
return jettyContext;
}
- public ReadOnlyContext getContext() {
- return context;
+ public ReadOnlyContext getComponentContext() {
+ return jettyContext.getComponentContext();
}
- public void setContext(ReadOnlyContext context) {
- this.context = context;
+ public void setComponentContext(ReadOnlyContext context) {
+ jettyContext.setComponentContext(context);
}
public void doStart() throws Exception {