jboynes 2003/11/15 18:25:37
Modified: modules/web/src/java/org/apache/geronimo/web
AbstractWebContainer.java
Log:
Do not use file extension to determine whether to examine the URL
instead use presence/absence of web.xml
Also format according to coding convention (please don't make this necessary)
Revision Changes Path
1.15 +135 -229
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractWebContainer.java 14 Nov 2003 16:27:34 -0000 1.14
+++ AbstractWebContainer.java 16 Nov 2003 02:25:36 -0000 1.15
@@ -57,8 +57,9 @@
package org.apache.geronimo.web;
import java.io.File;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -67,29 +68,28 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.management.Attribute;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
import javax.management.MBeanServerNotification;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.ObjectName;
import javax.management.ReflectionException;
-import javax.management.relation.Role;
+
+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.kernel.deployment.DeploymentException;
+import org.apache.geronimo.kernel.deployment.DeploymentPlan;
import org.apache.geronimo.kernel.deployment.goal.DeployURL;
-import org.apache.geronimo.kernel.deployment.goal.DeploymentGoal;
import org.apache.geronimo.kernel.deployment.goal.RedeployURL;
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.DestroyMBeanInstance;
@@ -98,10 +98,7 @@
import org.apache.geronimo.kernel.deployment.task.StopMBeanInstance;
import org.apache.geronimo.kernel.management.State;
import org.apache.geronimo.web.deploy.RemoveWebApplication;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
-import org.w3c.dom.Node;
/**
* AbstractWebContainer
@@ -122,11 +119,10 @@
* @version $Revision$ $Date$
*/
public abstract class AbstractWebContainer
- extends AbstractManagedContainer
- implements WebContainer, AbstractWebContainerMBean, MBeanRegistration
-{
+ extends AbstractManagedContainer
+ implements WebContainer, AbstractWebContainerMBean,
MBeanRegistration {
private final static Log log =
- LogFactory.getLog(AbstractWebContainer.class);
+ LogFactory.getLog(AbstractWebContainer.class);
/**
* Location of the default web.xml file
@@ -146,8 +142,7 @@
/*
--------------------------------------------------------------------------------------
*/
/**Constructor
*/
- public AbstractWebContainer()
- {
+ public AbstractWebContainer() {
}
/*
--------------------------------------------------------------------------------------
*/
@@ -158,53 +153,36 @@
* @param n a <code>Notification</code> value
* @param o an <code>Object</code> value
*/
- public void handleNotification(Notification n, Object o)
- {
+ public void handleNotification(Notification n, Object o) {
ObjectName source = null;
- try
- {
+ try {
//Respond to registrations of WebConnectors, WebAccessLogs and
WebApplications
//Call setContainer() on them which causes them to call
addComponent() on us and
//thus maintain the component/container hierarchy.
- if (MBeanServerNotification
.REGISTRATION_NOTIFICATION.equals(n.getType()))
- {
+ if
(MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(n.getType())) {
MBeanServerNotification notification =
- (MBeanServerNotification) n;
+ (MBeanServerNotification) n;
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));
- }
- else if (server.isInstanceOf(source,
WebAccessLog.class.getName()))
- {
- log.debug("Received registration notification for
weblog="+ source);
- server.setAttribute(source, new Attribute("Container",
(Container) this));
- }
- else if ( server.isInstanceOf(source,
WebApplication.class.getName()))
- {
- log.debug( "Received registration notification for
webapplication="+ source);
+ if (server.isInstanceOf(source,
WebConnector.class.getName())) {
+ log.debug("Received registration notification for
webconnecter=" + source);
server.setAttribute(source, new Attribute("Container",
(Container) this));
- }
- else
+ } else if (server.isInstanceOf(source,
WebAccessLog.class.getName())) {
+ log.debug("Received registration notification for
weblog=" + source);
+ server.setAttribute(source, new Attribute("Container",
(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));
+ } else
log.debug("Ignoring registration of mbean=" + source);
}
- }
- catch (InstanceNotFoundException e)
- {
- log.debug( "Registration notification received for non-existant
object: " + source);
- }
- catch (MBeanException e)
- {
+ } catch (InstanceNotFoundException e) {
+ log.debug("Registration notification received for non-existant
object: " + source);
+ } catch (MBeanException e) {
throw new IllegalStateException(e.toString());
- }
- catch (ReflectionException e)
- {
+ } catch (ReflectionException e) {
throw new IllegalStateException(e.toString());
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
throw new IllegalStateException(e.toString());
}
@@ -228,11 +206,10 @@
* @jmx.managed-operation
*/
public boolean deploy(DeployURL goal, Set goals, Set plans)
- throws DeploymentException
- {
+ throws DeploymentException {
if (getStateInstance() != State.RUNNING)
- throw new DeploymentException("WebContainer "+getObjectName()+"
cannot deploy as it is not RUNNING");
+ throw new DeploymentException("WebContainer " + getObjectName()
+ " cannot deploy as it is not RUNNING");
InputStream is;
URL url = goal.getUrl();
@@ -240,97 +217,68 @@
URLType type = goal.getType();
URL webXmlURL = null;
- //check it ends with ".war"
- if (!url.getPath().endsWith(".war"))
- return false;
-
- //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 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
- {
+ try {
URL webInfURL =
- new URL( "jar:" + url.toExternalForm() +
"!/WEB-INF/web.xml");
+ new URL("jar:" + url.toExternalForm() +
"!/WEB-INF/web.xml");
stream = webInfURL.openStream();
- }
- catch (IOException e)
- {
- throw new DeploymentException( "Failed to open stream for
URL: " + url, e);
- }
- finally
- {
- try
- {
+ } 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)
- {
+ } catch (IOException iox) {
throw new DeploymentException("Failed to close stream
for URL: " + url, iox);
}
}
- }
- else if (type == URLType.UNPACKED_ARCHIVE)
- {
+ } else if (type == URLType.UNPACKED_ARCHIVE) {
// check if there is a WEB-INF
InputStream stream = null;
- try
- {
+ try {
URL webInfURL = new URL(url, "WEB-INF/web.xml");
stream = webInfURL.openStream();
- }
- catch (IOException e)
- {
- throw new DeploymentException( "Failed to open stream for
URL: " + url,e);
- }
- finally
- {
- try
- {
+ } 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);
+ } catch (IOException iox) {
+ throw new DeploymentException("Failed to close stream
for URL: " + url, iox);
}
}
- }
- else if (type == URLType.RESOURCE)
- {
+ } 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;
+ if (!url.getPath().endsWith("web.xml"))
+ return false;
- try
- {
- File file = new File (url.toExternalForm());
+ try {
+ File file = new File(url.toExternalForm());
if (!file.exists())
- throw new DeploymentException ("No such file:"+url);
+ 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");
+ 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);
+ } 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
- {
+ } else {
//we can't deploy any other structure
return false;
}
@@ -339,52 +287,46 @@
//check to see if there is already a deployment for the webapp
ObjectName deploymentName = null;
- try
- {
+ try {
deploymentName =
- new ObjectName(
"geronimo.deployment:role=DeploymentUnit,url="
- + ObjectName.quote(url.toString())
- + ",type=WebApplication");
- }
- catch (MalformedObjectNameException e)
- {
+ new
ObjectName("geronimo.deployment:role=DeploymentUnit,url="
+ + ObjectName.quote(url.toString())
+ + ",type=WebApplication");
+ } catch (MalformedObjectNameException e) {
throw new DeploymentException(e);
}
if (server.isRegistered(deploymentName))
- throw new DeploymentException( "A web application deployment is
already registered at:"
- +
deploymentName.toString());
+ 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);
+ new WebDeployment(deploymentName, null, url);
deploymentUnitPlan.addTask(
- new RegisterMBeanInstance(server, deploymentName,
deploymentInfo));
+ new RegisterMBeanInstance(server, deploymentName,
deploymentInfo));
MBeanMetadata deploymentUnitMetadata =
- new MBeanMetadata(deploymentName);
+ new MBeanMetadata(deploymentName);
deploymentUnitPlan.addTask(
- new StartMBeanInstance(server, deploymentUnitMetadata));
+ new StartMBeanInstance(server, deploymentUnitMetadata));
plans.add(deploymentUnitPlan);
//Create a webapp typed to the concrete type of the web container
WebApplication webapp = createWebApplication(baseURI);
ObjectName webappName;
- try
- {
+ try {
webappName = new ObjectName(webapp.getObjectName());
- }
- catch (MalformedObjectNameException e)
- {
+ } 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));
+ 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
@@ -435,35 +377,30 @@
* @jmx.managed-operation
*/
public boolean remove(UndeployURL goal, Set goals, Set plans)
- throws DeploymentException
- {
+ throws DeploymentException {
//work out what the name of the deployment would be, assuming it is
a webapp
URL url = goal.getUrl();
- log.debug ("WebContainer "+getObjectName()+" checking for removal of
"+url);
+ log.debug("WebContainer " + getObjectName() + " checking for removal
of " + url);
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);
- }
+ try {
+ deploymentName = new
ObjectName("geronimo.deployment:role=DeploymentUnit,url="
+ + ObjectName.quote(url.toString())
+ + ",type=WebApplication");
+ } catch (MalformedObjectNameException e) {
+ throw new DeploymentException(e);
+ }
//check to see if it is registered - if it isn't then either it
isn't registered anymore, or
//it wasn't a webapp, so in either case there is nothing
//for us to do - let one of the other deployers try and handle it
- if (!server.isRegistered(deploymentName))
- {
- log.debug ("No deployment registered at: "+deploymentName);
+ if (!server.isRegistered(deploymentName)) {
+ log.debug("No deployment registered at: " + deploymentName);
return false;
}
- log.debug ("Deployment is registered");
+ log.debug("Deployment is registered");
//It is a webapp, and it is registered, so we should maybe undeploy
it
//so find out if it was in fact us that deployed it (could have been
a different web container)
@@ -473,45 +410,37 @@
List webapps = new ArrayList();
- log.debug ("there are "+deploymentChildren.size()+" children" );
+ log.debug("there are " + deploymentChildren.size() + " children");
Iterator itor = deploymentChildren.iterator();
- try
- {
- while (itor.hasNext())
- {
+ try {
+ while (itor.hasNext()) {
ObjectName childName = (ObjectName) itor.next();
- if (server.isInstanceOf(childName,
WebApplication.class.getName())
- &&
- (server.getAttribute(childName, "Container") ==
this))
- {
- log.debug ("Adding webapp for removal: "+ childName);
- webapps.add(childName);
- }
- else
- {
- log.debug ("Skipping "+childName);
- log.debug
("Container="+server.getAttribute(childName, "Container") +"this="+this);
- log.debug ("Webapp="+server.isInstanceOf(childName,
WebApplication.class.getName()));
- }
+ if (server.isInstanceOf(childName,
WebApplication.class.getName())
+ &&
+ (server.getAttribute(childName, "Container") ==
this)) {
+ log.debug("Adding webapp for removal: " + childName);
+ webapps.add(childName);
+ } else {
+ log.debug("Skipping " + childName);
+ log.debug("Container=" + server.getAttribute(childName,
"Container") + "this=" + this);
+ log.debug("Webapp=" + server.isInstanceOf(childName,
WebApplication.class.getName()));
}
- }
- catch (Exception e)
- {
- throw new DeploymentException (e);
+ }
+ } catch (Exception e) {
+ throw new DeploymentException(e);
}
- if (webapps.isEmpty())
- {
+ if (webapps.isEmpty()) {
//we didn't deploy anything so nothing for us to do
return false;
}
//we have webapps to undeploy, so check if we are able to
if (getStateInstance() != State.RUNNING)
- throw new DeploymentException ("WebContainer "+getObjectName()+"
cannot undeploy webapps because it is not RUNNING");
+ throw new DeploymentException("WebContainer " + getObjectName()
+ " cannot undeploy webapps because it is not RUNNING");
//put in a stoptask for the deployment unit, which will also stop
the webapp(s)
//because of the dependency between them
@@ -523,20 +452,19 @@
DeploymentPlan removePlan = new DeploymentPlan();
itor = webapps.iterator();
- while (itor.hasNext())
- {
+ while (itor.hasNext()) {
//unregister it
- ObjectName webappName = (ObjectName)itor.next();
- removePlan.addTask (new DestroyMBeanInstance (server,
webappName));
+ ObjectName webappName = (ObjectName) itor.next();
+ removePlan.addTask(new DestroyMBeanInstance(server, webappName));
//now remove it from the container
- removePlan.addTask (new RemoveWebApplication (server, this,
(WebApplication)webAppMap.get(webappName.toString())));
+ removePlan.addTask(new RemoveWebApplication(server, this,
(WebApplication) webAppMap.get(webappName.toString())));
}
//unregister the deployment itself
removePlan.addTask(new DestroyMBeanInstance(server, deploymentName));
- plans.add (removePlan);
+ plans.add(removePlan);
goals.remove(goal);
return true;
}
@@ -558,8 +486,7 @@
* @jmx.managed-operation
*/
public boolean redeploy(RedeployURL goal, Set goals)
- throws DeploymentException
- {
+ throws DeploymentException {
//TODO
goals.remove(goal);
return true;
@@ -579,8 +506,7 @@
/**Get the URI of the web defaults.
* @return the location of the default web.xml file for this container
*/
- public URI getDefaultWebXmlURI()
- {
+ public URI getDefaultWebXmlURI() {
return defaultWebXmlURI;
}
@@ -588,11 +514,10 @@
/*
--------------------------------------------------------------------------------------
*/
/** Set a uri of a web.xml containing defaults for this container.
- * @param uri the location of the default web.xml file
+ * @param uri the location of the default web.xml file
*/
- public void setDefaultWebXmlURI(URI uri)
- {
- log.debug( "DefaultWebXmlURI=" + (uri == null ? "null" :
uri.toString()));
+ public void setDefaultWebXmlURI(URI uri) {
+ log.debug("DefaultWebXmlURI=" + (uri == null ? "null" :
uri.toString()));
defaultWebXmlURI = uri;
}
@@ -602,8 +527,7 @@
*
* @return
*/
- public Document getDefaultWebXmlDoc()
- {
+ public Document getDefaultWebXmlDoc() {
return defaultWebXmlDoc;
}
@@ -616,8 +540,7 @@
* @param uri an <code>URI</code> value
* @return a <code>String</code> value
*/
- public String extractContextPath(URI uri)
- {
+ public String extractContextPath(URI uri) {
String path = uri.getPath();
if (path.endsWith("/"))
@@ -639,8 +562,7 @@
* Parse the web defaults descriptor
* @throws Exception
*/
- protected void parseWebDefaults() throws Exception
- {
+ protected void parseWebDefaults() throws Exception {
if (defaultWebXmlURI == null)
return;
@@ -653,20 +575,14 @@
* Add a component to this container's containment hierarchy
* @see
org.apache.geronimo.core.service.Container#addComponent(org.apache.geronimo.core.service.Component)
*/
- public void addComponent(Component component)
- {
+ public void addComponent(Component component) {
super.addComponent(component);
- if (component instanceof WebConnector)
- {
+ if (component instanceof WebConnector) {
webConnectorAdded((WebConnector) component);
- }
- else if (component instanceof WebApplication)
- {
+ } else if (component instanceof WebApplication) {
webApplicationAdded((WebApplication) component);
- }
- else if (component instanceof WebAccessLog)
- {
+ } else if (component instanceof WebAccessLog) {
webAccessLogAdded((WebAccessLog) component);
}
}
@@ -676,14 +592,10 @@
* 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)
- {
- if (component instanceof WebConnector)
- {
+ public void removeComponent(Component component) {
+ if (component instanceof WebConnector) {
webConnectorRemoval((WebConnector) component);
- }
- else if (component instanceof WebApplication)
- {
+ } else if (component instanceof WebApplication) {
webApplicationRemoval((WebApplication) component);
}
@@ -696,8 +608,7 @@
* Method called by addComponent after a WebConnector has been added.
* @param connector
*/
- protected void webConnectorAdded(WebConnector connector)
- {
+ protected void webConnectorAdded(WebConnector connector) {
}
@@ -706,17 +617,15 @@
* Method called by addComponment after a WebApplication has been added.
* @param app
*/
- protected void webApplicationAdded(WebApplication app)
- {
- webAppMap.put(((AbstractWebApplication)app).getObjectName(), app);
+ protected void webApplicationAdded(WebApplication app) {
+ webAppMap.put(((AbstractWebApplication) app).getObjectName(), app);
}
/*
--------------------------------------------------------------------------------------
*/
/**
* @param log
*/
- protected void webAccessLogAdded(WebAccessLog log)
- {
+ protected void webAccessLogAdded(WebAccessLog log) {
}
/*
--------------------------------------------------------------------------------------
*/
@@ -724,8 +633,7 @@
* Method called by removeComponent before a WebConnector has been
removed.
* @param connector
*/
- protected void webConnectorRemoval(WebConnector connector)
- {
+ protected void webConnectorRemoval(WebConnector connector) {
}
/*
--------------------------------------------------------------------------------------
*/
@@ -733,9 +641,8 @@
* Method called by removeComponment before a WebApplication has been
removed.
* @param app
*/
- protected void webApplicationRemoval(WebApplication app)
- {
- webAppMap.remove (((AbstractWebApplication)app).getObjectName());
+ protected void webApplicationRemoval(WebApplication app) {
+ webAppMap.remove(((AbstractWebApplication) app).getObjectName());
}
/*
--------------------------------------------------------------------------------------
*/
@@ -743,7 +650,6 @@
* Remove an access log service from the container
* @param log
*/
- protected void webAccessLogRemoval(WebAccessLog log)
- {
+ protected void webAccessLogRemoval(WebAccessLog log) {
}
}