janb 2003/09/28 15:30:58
Modified: modules/web/src/java/org/apache/geronimo/web
AbstractWebApplication.java
AbstractWebContainer.java WebApplication.java
WebContainer.java
modules/web/src/java/org/apache/geronimo/web/jetty
JettyWebApplication.java JettyWebContainer.java
Added: modules/web/src/java/org/apache/geronimo/web
WebDeployment.java
Log:
Adding ability to deploy a webapp. Almost there - still one problem with the
scanner giving
me the same webapp to deploy twice if the war exists at startup time. Hot
deploy works. Jsp
path is still messed up - Jetty wants javax.servlet etc classes on the system
classpath
but they aren't. Hot deploying a war without JSPs should work.
Revision Changes Path
1.8 +52 -15
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java
Index: AbstractWebApplication.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractWebApplication.java 14 Sep 2003 12:09:43 -0000 1.7
+++ AbstractWebApplication.java 28 Sep 2003 22:30:58 -0000 1.8
@@ -56,12 +56,12 @@
package org.apache.geronimo.web;
+
import java.net.URI;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.service.AbstractComponent;
-
+import org.apache.geronimo.core.service.Container;
/**
@@ -69,20 +69,44 @@
*
* Instances are created by a deployer. The deployer finds the
* WebContainer and associates it with the WebApplication.
- *
+ *
+ * @jmx:mbean extends="org.apache.geronimo.web.WebApplication,
org.apache.geronimo.kernel.management.StateManageable,
javax.management.MBeanRegistration"
* @version $Revision$ $Date$
*/
public abstract class AbstractWebApplication extends AbstractComponent
implements WebApplication {
- /**
+
+ private final static Log log =
LogFactory.getLog(AbstractWebApplication.class);
+
+ protected URI uri;
+
+
+ /**
* Class loading delegation model
*/
private boolean java2ClassloadingCompliance = false;
- private Context initialContext = null;
-
+
+ /**
+ * Creates a new <code>AbstractWebApplication</code> instance.
+ *
+ */
public AbstractWebApplication() {
-
+
}
+
+
+ /**
+ * Creates a new <code>AbstractWebApplication</code> instance.
+ *
+ * @param uri uri of the webapp
+ */
+ public AbstractWebApplication(URI uri) {
+ this.uri = uri;
+ }
+
+
+
+
/**
* Start the webapp. Called by the container or management interface
@@ -90,17 +114,23 @@
* @throws IllegalStateException
*/
public void doStart() throws Exception {
- if (getContainer() == null)
- throw new IllegalStateException("WebApplication must have a
container set before START can be called");
-
- //setup the webapp
+
}
/**
* Stop the webapp. Called by the container, or by mangement
* interface
*/
- public void doStop() {
+ public void doStop() throws Exception {
+ }
+
+
+
+
+
+ public URI getURI ()
+ {
+ return uri;
}
/**
@@ -142,6 +172,13 @@
}
+ public void setContainer (Container container)
+ {
+ super.setContainer(container);
+
+ container.addComponent (this);
+ }
+
}
1.9 +112 -80
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractWebContainer.java 14 Sep 2003 12:09:43 -0000 1.8
+++ AbstractWebContainer.java 28 Sep 2003 22:30:58 -0000 1.9
@@ -61,6 +61,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.List;
import java.util.HashSet;
@@ -91,6 +92,10 @@
import org.apache.geronimo.kernel.deployment.goal.UndeployURL;
import org.apache.geronimo.kernel.deployment.DeploymentPlan;
import org.apache.geronimo.kernel.deployment.scanner.URLType;
+import org.apache.geronimo.kernel.deployment.service.MBeanMetadata;
+import org.apache.geronimo.kernel.deployment.task.RegisterMBeanInstance;
+import org.apache.geronimo.kernel.deployment.task.StartMBeanInstance;
+import org.apache.geronimo.kernel.management.State;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
@@ -163,9 +168,6 @@
new Role("DeploymentPlanner", planners));
log.trace ("Registered WebContainer as a DeploymentPlanner");
} catch (Exception e) {
-
- log.error ("XX: ", e);
-
IllegalStateException e1 = new IllegalStateException();
e1.initCause(e);
throw e1;
@@ -202,7 +204,8 @@
ObjectName source = null;
try
- {
+ {
+
//check for registrations of web connectors and web logs
if
(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(n.getType()))
{
@@ -212,24 +215,34 @@
{
log.debug ("Received registration notification for
webconnecter="+source);
-
-
// set up the Container on the Connector to be us
// this will result in the Connector adding itself to
// our containment hierarchy
server.setAttribute (source,
new Attribute ("Container",
(Container)this));
+
}
else if (server.isInstanceOf (source,
WebAccessLog.class.getName()))
{
// set up the Container on the WebAccessLog to be us
// this will result in the WebAccessLog adding itself to
- // our containment hierarchy
- server.invoke (source,
- "setContainer", new Object[]{this},
- new
String[]{"org.apache.geronimo.core.service.Container" });
+ // our containment hierarchy
+ log.debug ("Received registration notification for
weblog="+source);
+ server.setAttribute (source,
+ new Attribute ("Container",
+ (Container)this));
}
+ else if (server.isInstanceOf (source,
WebApplication.class.getName()))
+ {
+ //add the webapp as a component of the container
+ log.debug ("Received registration notification for
webapplication="+source);
+ server.setAttribute (source,
+ new Attribute ("Container",
+ (Container)this));
+ }
+ else
+ log.debug ("Ignoring registration of mbean="+source);
}
}
catch (InstanceNotFoundException e)
@@ -293,6 +306,10 @@
* @exception DeploymentException if an error occurs
*/
public boolean deploy (DeployURL goal, Set goals, Set plans) throws
DeploymentException {
+
+ if (getStateInstance() != State.RUNNING)
+ throw new DeploymentException ("WebContainer is not in RUNNING
state");
+
InputStream is;
URL url = goal.getUrl();
URI baseURI = URI.create(url.toString()).normalize();;
@@ -301,9 +318,8 @@
URL webXmlURL = null;
- // this won't work for ear deployments where the application.xml
- // specifies a contextpath - how do we get it?
-
+ //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)
{
//check it ends with ".war"
@@ -313,7 +329,7 @@
InputStream stream = null;
try
{
- URL webInfURL = new URL (url, "WEB-INF");
+ URL webInfURL = new URL
("jar:"+url.toExternalForm()+"!/WEB-INF/web.xml");
stream = webInfURL.openStream();
}
catch (IOException e)
@@ -339,7 +355,7 @@
InputStream stream = null;
try
{
- URL webInfURL = new URL (url, "WEB-INF");
+ URL webInfURL = new URL (url, "WEB-INF/web.xml");
stream = webInfURL.openStream();
}
catch (IOException e)
@@ -365,12 +381,14 @@
return false;
}
- //check to see if the webapp has already been deployed
+ log.debug (Thread.currentThread()+":Identified webapp to deploy");
+
+ //check to see if there is already a deployment for the webapp
ObjectName deploymentName = null;
try
{
- deploymentName = new
ObjectName("geronimo.deployment:role=DeploymentUnit,type=WebApplication,url="
- +
ObjectName.quote(url.toString()));
+ deploymentName = new
ObjectName("geronimo.deployment:role=DeploymentUnit,url="
+ +
ObjectName.quote(url.toString())+",type=WebApplication");
}
catch (MalformedObjectNameException e)
{
@@ -378,51 +396,64 @@
}
if (server.isRegistered(deploymentName))
- throw new DeploymentException ("Web app already deployed at
URL:"+url);
-
- // steps in the deployment plan for a web container are:
- // 1. create web app
- // 2. create class loader and set it for the webapp
- // 3. setup enc and set it for the webapp
- // 4. start the webapp?
+ throw new DeploymentException ("A web application deployment is
already registered at:"+deploymentName.toString());
+
+ //Set up the deployment itself in JMX
+ 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);
+
+
+ //Deploy the webapp itself
+ // create a webapp typed to the concrete type of the web container
+ WebApplication webapp = createWebApplication (baseURI);
+ ObjectName webappName;
+ try
+ {
+ webappName = new ObjectName (webapp.getObjectName());
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new DeploymentException (e);
+ }
+ // Create a deployment plan for the webapp
+ DeploymentPlan webappPlan = new DeploymentPlan();
+ webappPlan.addTask (new RegisterMBeanInstance(server, webappName,
webapp));
- // create a webapp typed to the concrete type of the web container
- WebApplication webapp = createWebApplication ();
+ MBeanMetadata webappMetadata = new MBeanMetadata (webappName);
+ webappMetadata.setParentName (deploymentName);
+ dependencyService.addStartDependency(webappName, deploymentName);
-
- //do the config setup of the webapp
- //NB. it would be nice to use the ServiceDeploymentPlanner to
- //do these - look into setting up appropriate MetaData etc
- //to call it on the fly
-
- //need to set the URI on the webapp
- URI webappURI = null;
- webapp.setURI (webappURI);
+ // crack open the war and read the web.xml and geronimo-web.xml into
the POJOs
+ //TBD
//contextPath can come from:
// application.xml
// geronimo-web.xml
// name of the war (without .war extension) or webapp dir
+ //For now, only support the name of the webapp
+ webapp.setContextPath(extractContextPath (baseURI));
- String contextPath = null;
- webapp.setContextPath(contextPath);
+ // Set up the parent classloader for the webapp
+ webapp.setParentClassLoader (getClass().getClassLoader());
- // How do we identify which is the parent classloader???
- webapp.setParentClassLoader
(Thread.currentThread().getContextClassLoader());
- //when to add the webapp??
- addComponent (webapp);
+ //Set up the ENC etc
+ //TBD
- // Create a deployment plan
- DeploymentPlan deploymentUnitPlan = new DeploymentPlan();
-
- // add a task to start the webapp which will finish configuring it
- //NB: is this OK? What happens if start task gets called after
webapp already started?
- //deploymentUnitPlan.addTask (new StartWebAppTask (server, this,
webapp, deploymentName));
- plans.add (deploymentUnitPlan);
+
+ //Add a task to start the webapp which will finish configuring it
+ //NOTE: the class loader will be null, which will cause the
+ //mbean server's class loader to be used for the start call.
+ //Is this going to be a problem?
+ webappPlan.addTask (new StartMBeanInstance (server, webappMetadata));
+ plans.add (webappPlan);
goals.remove(goal);
return true;
@@ -430,48 +461,23 @@
// TODO
- private boolean remove(UndeployURL goal, Set goals, Set plans) throws
DeploymentException {
+ private boolean remove(UndeployURL goal, Set goals, Set plans) throws
DeploymentException {
+ goals.remove(goal);
return true;
}
// TODO
private boolean redeploy(RedeployURL goal, Set goals) throws
DeploymentException {
-
+ goals.remove(goal);
return true;
}
- /*
--------------------------------------------------------------------------------------
*/
- /**
- * Creates a WebApplication from the url and associates it with this
container.
- * @param url the location of the web application to deploy
- * @throws Exception
- * @see org.apache.geronimo.web.WebContainer#deploy(java.lang.String)
- * @todo this is likely to change when the deployment interface becomes
available
- */
- public void deploy(String uri) throws Exception {
- //TODO what will be the interface to the deployer?
-
- //sort out the contextPath - if the geronimo web descriptor doesn't
- //provide one, and there is no application descriptor, then it will
be
- //the name of the webapp. NOTE, we need to somehow access
- //these descriptors - is it by JSR88 beans or by xml?
- String contextPath = null;
-
- //this is only necessary for compilation, the interface to the
deployer will change
- URI location = new URI(uri);
-
- WebApplication webapp = createWebApplication();
- webapp.setURI(location);
- webapp.setContextPath(contextPath);
- addComponent(webapp);
- }
-
/**
* Create a WebApplication suitable to the container's type.
* @return WebApplication instance, preferably derived from
AbstractWebApplication suitable to the container
*/
- public abstract WebApplication createWebApplication();
+ public abstract WebApplication createWebApplication(URI baseURI);
/**
* Get the URI of the web defaults.
@@ -500,6 +506,32 @@
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)
+ {
+
+ String path = uri.getPath();
+
+ if (path.endsWith("/"))
+ path = path.substring (0, path.length() - 1);
+
+ int sepIndex = path.lastIndexOf ('/');
+ if (sepIndex > 0)
+ path = path.substring (sepIndex+1);
+
+ if (path.endsWith(".war"))
+ path = path.substring (0, path.length()-4);
+
+ return "/"+path;
+ }
+
+
/**
* Parse the web defaults descriptor
* @throws Exception
@@ -508,7 +540,7 @@
if (defaultWebXmlURI == null)
return;
- //defaultWebXmlDoc = parser.parse(defaultWebXmlURI.toString());
+ //TODO
}
1.8 +1 -2
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebApplication.java 14 Sep 2003 12:09:43 -0000 1.7
+++ WebApplication.java 28 Sep 2003 22:30:58 -0000 1.8
@@ -76,7 +76,6 @@
*/
public URI getURI();
- public void setURI(URI uri);
public void setParentClassLoader (ClassLoader loader);
1.7 +2 -8
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebContainer.java
Index: WebContainer.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebContainer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WebContainer.java 14 Sep 2003 12:09:43 -0000 1.6
+++ WebContainer.java 28 Sep 2003 22:30:58 -0000 1.7
@@ -70,13 +70,7 @@
*/
public interface WebContainer extends Container {
- /**
- * Deploy a web application. Convenience method to
- * have the container create the WebApplication and add it to itself.
- * @param uri
- * @throws Exception
- */
- public void deploy(String uri) throws Exception;
+
/**
* Set up a web.xml descriptor for the Container to use as defaults.
1.1
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebDeployment.java
Index: WebDeployment.java
===================================================================
package org.apache.geronimo.web;
import java.net.URL;
import javax.management.ObjectName;
import org.apache.geronimo.kernel.deployment.DeploymentInfo;
/**
* WebDeploymentInfo.java
*
* This class is registered with the mbean server as
* the parent of a deployment unit (a web app).
* @jmx:mbean
* extends="org.apache.geronimo.kernel.deployment.DeploymentInfoMBean"
*
* @version $Revision: 1.1 $ $Date: 2003/09/28 22:30:58 $
*
*/
public class WebDeployment extends DeploymentInfo implements
WebDeploymentMBean
{
public WebDeployment (ObjectName name, ObjectName parent, URL url)
{
super (name, parent, url);
}
}
1.2 +67 -31
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JettyWebApplication.java 14 Sep 2003 12:09:44 -0000 1.1
+++ JettyWebApplication.java 28 Sep 2003 22:30:58 -0000 1.2
@@ -1,9 +1,15 @@
package org.apache.geronimo.web.jetty;
import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.service.AbstractComponent;
import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.web.WebApplication;
+import org.apache.geronimo.web.AbstractWebApplication;
import org.mortbay.jetty.servlet.WebApplicationContext;
@@ -14,57 +20,71 @@
*
* Created: Sun Sep 14 16:40:17 2003
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Jan Bartel</a>
- * @version 1.0
+ * @jmx:mbean extends="org.apache.geronimo.web.AbstractWebApplicationMBean
+ * @version $Revision$ $Date$
*/
-public class JettyWebApplication extends AbstractComponent implements
WebApplication
+public class JettyWebApplication extends AbstractWebApplication implements
JettyWebApplicationMBean
{
- private WebApplicationContext _jettyContext = null;
- private URI _uri = null;
+ private WebApplicationContext jettyContext = null;
+ private final Log log = LogFactory.getLog(getClass());
-
- public JettyWebApplication()
+ public JettyWebApplication ()
{
- _jettyContext = new WebApplicationContext();
+ super();
+ jettyContext = new WebApplicationContext ();
+
+ try
+ {
+ objectName = new ObjectName ("jetty:role=WebApplication,
instance="+hashCode());
+ }
+ catch (Exception e)
+ {
+ log.warn (e.getMessage());
+ }
+ }
+
+ public JettyWebApplication(URI uri)
+ {
+ super(uri);
+ jettyContext = new WebApplicationContext(uri.toString());
+
+ try
+ {
+ objectName = new ObjectName ("jetty:role=WebApplication,
uri="+ObjectName.quote(uri.toString()));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException (e.getMessage());
+ }
}
-
- public void setURI (URI uri)
- {
- _uri = uri;
- _jettyContext.setWAR (_uri.toString());
- }
-
- public URI getURI ()
- {
- return _uri;
+
+ public ObjectName preRegister (MBeanServer server, ObjectName
objectName) throws Exception
+ {
+ return super.preRegister (server,objectName);
}
public void setParentClassLoader (ClassLoader loader)
{
- _jettyContext.setParentClassLoader (loader);
+ jettyContext.setParentClassLoader (loader);
}
public ClassLoader getParentClassLoader()
{
- return _jettyContext.getParentClassLoader();
+ return jettyContext.getParentClassLoader();
}
- public String[] getServlets ()
- {
- //TODO
- return null;
- }
+
public void setContextPath (String path)
{
- _jettyContext.setContextPath(path);
+ jettyContext.setContextPath(path);
}
public String getContextPath ()
{
- return _jettyContext.getContextPath();
+ return jettyContext.getContextPath();
}
@@ -78,17 +98,33 @@
public boolean getJava2ClassloadingCompliance ()
{
- return _jettyContext.isClassLoaderJava2Compliant();
+ return jettyContext.isClassLoaderJava2Compliant();
}
public void setJava2ClassloadingCompliance (boolean state)
{
- _jettyContext.setClassLoaderJava2Compliant(state);
+ jettyContext.setClassLoaderJava2Compliant(state);
}
WebApplicationContext getJettyContext ()
{
- return _jettyContext;
+ return jettyContext;
+ }
+
+
+ public void doStart () throws Exception
+ {
+ super.doStart();
+ jettyContext.start();
+
+ log.debug (jettyContext.getFileClassPath());
+ }
+
+
+ public void doStop () throws Exception
+ {
+ super.doStop();
+ jettyContext.stop();
}
}
1.6 +11 -3
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebContainer.java
Index: JettyWebContainer.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebContainer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JettyWebContainer.java 14 Sep 2003 12:09:44 -0000 1.5
+++ JettyWebContainer.java 28 Sep 2003 22:30:58 -0000 1.6
@@ -109,9 +109,9 @@
}
- public WebApplication createWebApplication ()
+ public WebApplication createWebApplication (URI uri)
{
- return new JettyWebApplication();
+ return new JettyWebApplication(uri);
}
@@ -164,4 +164,12 @@
_jettyServer.removeListener
(((JettyWebConnector)connector).getListener());
}
+
+ protected void webApplicationAdded (WebApplication webapp)
+ {
+ _log.debug ("Web application="+webapp.getObjectName()+" added to
Jetty");
+ _jettyServer.addContext
(((JettyWebApplication)webapp).getJettyContext());
+ ((JettyWebApplication)webapp).getJettyContext().setExtractWAR(true);
+ super.webApplicationAdded (webapp);
+ }
}