You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jb...@apache.org on 2004/01/26 06:55:27 UTC
cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config ConfigurationParent.java
jboynes 2004/01/25 21:55:27
Modified: modules/deployment/src/java/org/apache/geronimo/deployment/plugin
DeploymentManagerImpl.java DeploymentServer.java
DisconnectedServer.java
modules/deployment/src/java/org/apache/geronimo/deployment/plugin/application
EARConfigurationFactory.java
modules/deployment/src/java/org/apache/geronimo/deployment/plugin/client
ClientConfigurationFactory.java
modules/deployment/src/java/org/apache/geronimo/deployment/plugin/factories
DeploymentConfigurationFactory.java
modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local
DistributeCommand.java LocalServer.java
StopCommand.java
modules/jetty/src/java/org/apache/geronimo/jetty
JettyWebApplicationContext.java
modules/jetty/src/java/org/apache/geronimo/jetty/deployment
AbstractModule.java JettyModule.java
UnpackedModule.java WARConfigurationFactory.java
modules/jetty/src/test/org/apache/geronimo/jetty
ApplicationTest.java
modules/jetty/src/test/org/apache/geronimo/jetty/deployment
DeploymentTest.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
ConfigurationParent.java
Log:
Support for packed WAR files in Jetty
This required having the DeploymentManager create the configID which is then passed down
Revision Changes Path
1.7 +26 -6 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DeploymentManagerImpl.java
Index: DeploymentManagerImpl.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DeploymentManagerImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DeploymentManagerImpl.java 25 Jan 2004 21:07:03 -0000 1.6
+++ DeploymentManagerImpl.java 26 Jan 2004 05:55:26 -0000 1.7
@@ -59,6 +59,8 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -82,7 +84,7 @@
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.deployment.DeploymentModule;
import org.apache.geronimo.deployment.plugin.factories.DeploymentConfigurationFactory;
-import org.apache.geronimo.deployment.plugin.local.CommandSupport;
+import org.apache.geronimo.deployment.util.XMLUtil;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.GConstructorInfo;
@@ -188,11 +190,17 @@
} catch (Exception e) {
return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
}
+ URI configID;
+ try {
+ configID = getConfigID(doc);
+ } catch (URISyntaxException e) {
+ return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
+ }
DeploymentModule module = null;
for (Iterator i = configurationFactories.values().iterator(); i.hasNext();) {
DeploymentConfigurationFactory factory = (DeploymentConfigurationFactory) i.next();
try {
- module = factory.createModule(moduleArchive, doc);
+ module = factory.createModule(moduleArchive, doc, configID, server.isLocal());
} catch (DeploymentException e) {
return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
}
@@ -200,7 +208,7 @@
if (module == null) {
return new FailedProgressObject(CommandType.DISTRIBUTE, "No deployer found for supplied plan");
}
- return server.distribute(targetList, module);
+ return server.distribute(targetList, module, configID);
}
public ProgressObject distribute(Target[] targetList, InputStream moduleArchive, InputStream deploymentPlan) throws IllegalStateException {
@@ -211,11 +219,17 @@
} catch (Exception e) {
return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
}
+ URI configID;
+ try {
+ configID = getConfigID(doc);
+ } catch (URISyntaxException e) {
+ return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
+ }
DeploymentModule module = null;
for (Iterator i = configurationFactories.values().iterator(); i.hasNext();) {
DeploymentConfigurationFactory factory = (DeploymentConfigurationFactory) i.next();
try {
- module = factory.createModule(moduleArchive, doc);
+ module = factory.createModule(moduleArchive, doc, configID);
} catch (DeploymentException e) {
return new FailedProgressObject(CommandType.DISTRIBUTE, e.getMessage());
}
@@ -223,7 +237,7 @@
if (module == null) {
return new FailedProgressObject(CommandType.DISTRIBUTE, "No deployer found for supplied plan");
}
- return server.distribute(targetList, module);
+ return server.distribute(targetList, module, configID);
}
public ProgressObject start(TargetModuleID[] moduleIDList) throws IllegalStateException {
@@ -258,6 +272,12 @@
public void release() {
server.release();
// @todo shut down the deployment kernel
+ }
+
+ private URI getConfigID(Document doc) throws URISyntaxException {
+ String id = Long.toString(System.currentTimeMillis()); // unique enough one hopes
+ id = XMLUtil.getChildContent(doc.getDocumentElement(), "config-id", id, id);
+ return new URI(id);
}
public static final GBeanInfo GBEAN_INFO;
1.2 +3 -2 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DeploymentServer.java
Index: DeploymentServer.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DeploymentServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DeploymentServer.java 23 Jan 2004 19:58:16 -0000 1.1
+++ DeploymentServer.java 26 Jan 2004 05:55:26 -0000 1.2
@@ -56,6 +56,7 @@
package org.apache.geronimo.deployment.plugin;
import java.io.InputStream;
+import java.net.URI;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
@@ -80,7 +81,7 @@
public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] targetList) throws TargetException, IllegalStateException;
- public ProgressObject distribute(Target[] targetList, DeploymentModule module) throws IllegalStateException;
+ public ProgressObject distribute(Target[] targetList, DeploymentModule module, URI configID) throws IllegalStateException;
public ProgressObject start(TargetModuleID[] moduleIDList) throws IllegalStateException;
1.2 +3 -2 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DisconnectedServer.java
Index: DisconnectedServer.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DisconnectedServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DisconnectedServer.java 23 Jan 2004 19:58:16 -0000 1.1
+++ DisconnectedServer.java 26 Jan 2004 05:55:26 -0000 1.2
@@ -56,6 +56,7 @@
package org.apache.geronimo.deployment.plugin;
import java.io.InputStream;
+import java.net.URI;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
@@ -92,7 +93,7 @@
throw new IllegalStateException("Disconnected");
}
- public ProgressObject distribute(Target[] targetList, DeploymentModule module) throws IllegalStateException {
+ public ProgressObject distribute(Target[] targetList, DeploymentModule module, URI configID) throws IllegalStateException {
throw new IllegalStateException("Disconnected");
}
1.4 +4 -3 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/application/EARConfigurationFactory.java
Index: EARConfigurationFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/application/EARConfigurationFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EARConfigurationFactory.java 24 Jan 2004 21:07:44 -0000 1.3
+++ EARConfigurationFactory.java 26 Jan 2004 05:55:26 -0000 1.4
@@ -57,6 +57,7 @@
import java.io.InputStream;
import java.io.File;
+import java.net.URI;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
@@ -83,11 +84,11 @@
return new EARConfiguration(deployable);
}
- public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan, URI configID) throws DeploymentException {
throw new UnsupportedOperationException();
}
- public DeploymentModule createModule(File moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(File moduleArchive, Document deploymentPlan, URI configID, boolean isLocal) throws DeploymentException {
throw new UnsupportedOperationException();
}
1.4 +4 -3 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/client/ClientConfigurationFactory.java
Index: ClientConfigurationFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/client/ClientConfigurationFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClientConfigurationFactory.java 24 Jan 2004 21:07:44 -0000 1.3
+++ ClientConfigurationFactory.java 26 Jan 2004 05:55:26 -0000 1.4
@@ -57,6 +57,7 @@
import java.io.InputStream;
import java.io.File;
+import java.net.URI;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
import javax.enterprise.deploy.model.DeployableObject;
@@ -76,11 +77,11 @@
return null;
}
- public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan, URI configID) throws DeploymentException {
throw new UnsupportedOperationException();
}
- public DeploymentModule createModule(File moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(File moduleArchive, Document deploymentPlan, URI configID, boolean isLocal) throws DeploymentException {
throw new UnsupportedOperationException();
}
1.4 +4 -3 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/factories/DeploymentConfigurationFactory.java
Index: DeploymentConfigurationFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/factories/DeploymentConfigurationFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeploymentConfigurationFactory.java 24 Jan 2004 21:07:44 -0000 1.3
+++ DeploymentConfigurationFactory.java 26 Jan 2004 05:55:26 -0000 1.4
@@ -57,6 +57,7 @@
import java.io.InputStream;
import java.io.File;
+import java.net.URI;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
import javax.enterprise.deploy.spi.Target;
@@ -74,7 +75,7 @@
public interface DeploymentConfigurationFactory {
public DeploymentConfiguration createConfiguration(DeployableObject deployable) throws InvalidModuleException;
- public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan) throws DeploymentException;
+ public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan, URI configID) throws DeploymentException;
- public DeploymentModule createModule(File moduleArchive, Document deploymentPlan) throws DeploymentException;
+ public DeploymentModule createModule(File moduleArchive, Document deploymentPlan, URI configID, boolean isLocal) throws DeploymentException;
}
1.3 +6 -5 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java
Index: DistributeCommand.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DistributeCommand.java 24 Jan 2004 21:07:44 -0000 1.2
+++ DistributeCommand.java 26 Jan 2004 05:55:26 -0000 1.3
@@ -79,13 +79,15 @@
public class DistributeCommand extends CommandSupport {
private final Target target;
private final ConfigurationParent parent;
+ private final URI configID;
private final Kernel kernel;
private final DeploymentModule module;
- public DistributeCommand(Target target, ConfigurationParent parent, Kernel kernel, DeploymentModule module) {
+ public DistributeCommand(Target target, ConfigurationParent parent, URI configID, Kernel kernel, DeploymentModule module) {
super(CommandType.DISTRIBUTE);
this.target = target;
this.parent = parent;
+ this.configID = configID;
this.kernel = kernel;
this.module = module;
}
@@ -102,9 +104,8 @@
workDir.mkdir();
// convert the module to a Configuration
- TargetModuleID targetID = new TargetModuleIDImpl(target, "test");
- URI moduleID = URI.create(targetID.getModuleID());
- ModuleDeployer deployer = new ModuleDeployer(parent, moduleID, workDir);
+ TargetModuleID targetID = new TargetModuleIDImpl(target, configID.toString());
+ ModuleDeployer deployer = new ModuleDeployer(parent, configID, workDir);
deployer.addModule(module);
deployer.deploy();
1.3 +3 -3 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/LocalServer.java
Index: LocalServer.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/LocalServer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LocalServer.java 24 Jan 2004 21:07:44 -0000 1.2
+++ LocalServer.java 26 Jan 2004 05:55:26 -0000 1.3
@@ -129,11 +129,11 @@
return null;
}
- public ProgressObject distribute(Target[] targetList, DeploymentModule module) throws IllegalStateException {
+ public ProgressObject distribute(Target[] targetList, DeploymentModule module, URI configID) throws IllegalStateException {
if (targetList.length != 1 || !target.equals(targetList[0])) {
return new FailedProgressObject(CommandType.DISTRIBUTE, "Invalid Target");
}
- DistributeCommand command = new DistributeCommand(target, parent, kernel, module);
+ DistributeCommand command = new DistributeCommand(target, parent, configID, kernel, module);
new Thread(command).start();
return command;
}
1.2 +2 -2 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/StopCommand.java
Index: StopCommand.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/StopCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StopCommand.java 24 Jan 2004 21:07:44 -0000 1.1
+++ StopCommand.java 26 Jan 2004 05:55:26 -0000 1.2
@@ -83,7 +83,7 @@
TargetModuleID module = modules[i];
URI moduleID = URI.create(module.getModuleID());
- ObjectName name = kernel.getConfigObjectName(moduleID);
+ ObjectName name = Kernel.getConfigObjectName(moduleID);
kernel.getMBeanServer().invoke(name, "stop", null, null);
addModule(module);
}
1.6 +21 -9 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java
Index: JettyWebApplicationContext.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JettyWebApplicationContext.java 25 Jan 2004 21:07:04 -0000 1.5
+++ JettyWebApplicationContext.java 26 Jan 2004 05:55:26 -0000 1.6
@@ -55,14 +55,14 @@
*/
package org.apache.geronimo.jetty;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
-import java.net.URI;
-import java.io.IOException;
-
import javax.resource.ResourceException;
import javax.security.jacc.PolicyContext;
import javax.transaction.RollbackException;
@@ -77,17 +77,18 @@
import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBean;
+import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.GConstructorInfo;
import org.apache.geronimo.gbean.GReferenceInfo;
import org.apache.geronimo.gbean.WaitingException;
-import org.apache.geronimo.gbean.GBeanContext;
+import org.apache.geronimo.kernel.config.ConfigurationParent;
import org.apache.geronimo.naming.java.ReadOnlyContext;
import org.apache.geronimo.naming.java.RootContext;
+import org.mortbay.http.HttpException;
import org.mortbay.http.HttpRequest;
import org.mortbay.http.HttpResponse;
-import org.mortbay.http.HttpException;
import org.mortbay.jetty.servlet.WebApplicationContext;
/**
@@ -96,6 +97,8 @@
* @version $Revision$ $Date$
*/
public class JettyWebApplicationContext extends WebApplicationContext implements GBean {
+ private final ConfigurationParent config;
+ private final URI uri;
private final JettyContainer container;
private final ReadOnlyContext componentContext;
private final String policyContextID;
@@ -110,13 +113,16 @@
public JettyWebApplicationContext(
+ ConfigurationParent config,
URI uri,
JettyContainer container,
ReadOnlyContext compContext,
String policyContextID,
TransactionManager txManager,
TrackedConnectionAssociator associator) {
- super(uri.toString());
+ super();
+ this.config = config;
+ this.uri = uri;
this.container = container;
this.componentContext = compContext;
this.policyContextID = policyContextID;
@@ -194,6 +200,11 @@
}
public void doStart() throws WaitingException, Exception {
+ if (uri.isAbsolute()) {
+ setWAR(uri.toString());
+ } else {
+ setWAR(new URL(config.getBaseURL(), uri.toString()).toString());
+ }
container.addContext(this);
super.start();
}
@@ -226,12 +237,13 @@
infoFactory.addAttribute(new GAttributeInfo("ContextPath", true));
infoFactory.addAttribute(new GAttributeInfo("ComponentContext", true));
infoFactory.addAttribute(new GAttributeInfo("PolicyContextID", true));
+ infoFactory.addReference(new GReferenceInfo("Configuration", ConfigurationParent.class.getName()));
infoFactory.addReference(new GReferenceInfo("JettyContainer", JettyContainer.class.getName()));
infoFactory.addReference(new GReferenceInfo("TransactionManager", TransactionManager.class.getName()));
infoFactory.addReference(new GReferenceInfo("TrackedConnectionAssociator", TrackedConnectionAssociator.class.getName()));
infoFactory.setConstructor(new GConstructorInfo(
- Arrays.asList(new Object[]{"URI", "JettyContainer", "ComponentContext", "PolicyContextID", "TransactionManager", "TrackedConnectionAssociator"}),
- Arrays.asList(new Object[]{URI.class, JettyContainer.class, ReadOnlyContext.class, String.class, TransactionManager.class, TrackedConnectionAssociator.class})));
+ Arrays.asList(new Object[]{"Configuration", "URI", "JettyContainer", "ComponentContext", "PolicyContextID", "TransactionManager", "TrackedConnectionAssociator"}),
+ Arrays.asList(new Object[]{ConfigurationParent.class, URI.class, JettyContainer.class, ReadOnlyContext.class, String.class, TransactionManager.class, TrackedConnectionAssociator.class})));
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.3 +8 -1 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java
Index: AbstractModule.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractModule.java 25 Jan 2004 21:07:04 -0000 1.2
+++ AbstractModule.java 26 Jan 2004 05:55:27 -0000 1.3
@@ -66,6 +66,7 @@
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.jetty.JettyWebApplicationContext;
+import org.apache.geronimo.kernel.Kernel;
/**
*
@@ -73,9 +74,14 @@
* @version $Revision$ $Date$
*/
public class AbstractModule implements DeploymentModule {
+ protected final URI configID;
protected URI uri;
protected String contextPath;
+ public AbstractModule(URI configID) {
+ this.configID = configID;
+ }
+
public void init() throws DeploymentException {
}
@@ -97,6 +103,7 @@
app.setAttribute("ContextPath", contextPath);
app.setAttribute("ComponentContext", null);
app.setAttribute("PolicyContextID", null);
+ app.setReferencePatterns("Configuration", Collections.singleton(Kernel.getConfigObjectName(configID)));
app.setReferencePatterns("JettyContainer", Collections.singleton(new ObjectName("geronimo.web:type=WebContainer,container=Jetty"))); // @todo configurable
app.setReferencePatterns("TransactionManager", Collections.EMPTY_SET);
app.setReferencePatterns("TrackedConnectionAssociator", Collections.EMPTY_SET);
1.5 +116 -10 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java
Index: JettyModule.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JettyModule.java 24 Jan 2004 21:07:44 -0000 1.4
+++ JettyModule.java 26 Jan 2004 05:55:27 -0000 1.5
@@ -55,13 +55,19 @@
*/
package org.apache.geronimo.jetty.deployment;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.DeploymentException;
+import org.apache.geronimo.deployment.util.XMLUtil;
import org.w3c.dom.Document;
/**
@@ -70,22 +76,122 @@
* @version $Revision$ $Date$
*/
public class JettyModule extends AbstractModule {
- private final InputStream moduleArchive;
+ private final File moduleDirectory;
+ private final ZipInputStream zipArchive;
+ private final boolean closeStream;
+ private URI classes;
+ private URI lib;
+
+ public JettyModule(URI configID, InputStream moduleArchive, Document deploymentPlan) throws DeploymentException {
+ super(configID);
+ moduleDirectory = null;
+ this.zipArchive = new ZipInputStream(moduleArchive);
+ closeStream = false;
+ contextPath = XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", null, null);
+ if (contextPath == null) {
+ throw new DeploymentException("No context root specified");
+ }
+ }
+
+ public JettyModule(URI configID, File archiveFile, Document deploymentPlan) throws DeploymentException {
+ super(configID);
+ if (!archiveFile.isDirectory()) {
+ moduleDirectory = null;
+ try {
+ this.zipArchive = new ZipInputStream(new BufferedInputStream(new FileInputStream(archiveFile)));
+ closeStream = false;
+ } catch (FileNotFoundException e) {
+ throw new DeploymentException("Could not open module archive", e);
+ }
+ } else {
+ moduleDirectory = archiveFile;
+ this.zipArchive = null;
+ closeStream = false;
+ }
+
+ contextPath = archiveFile.getName();
+ if (contextPath.endsWith(".war")) {
+ contextPath = contextPath.substring(0, contextPath.length() - 4);
+ }
+ contextPath = XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", contextPath, contextPath);
+ }
- public JettyModule(InputStream moduleArchive, Document deploymentPlan) {
- this.moduleArchive = moduleArchive;
+ public void init() throws DeploymentException {
+ super.init();
+
+ uri = URI.create(contextPath + "/");
+ classes = uri.resolve("WEB-INF/classes/");
+ lib = uri.resolve("WEB-INF/lib/");
}
public void generateClassPath(ConfigurationCallback callback) throws DeploymentException {
- ZipInputStream zis = new ZipInputStream(moduleArchive);
- try {
- ZipEntry entry;
- while ((entry = zis.getNextEntry()) != null) {
+ if (zipArchive != null) {
+ // unpack archive into Configuration
+ try {
+ ZipEntry entry;
+ boolean addedClasses = false;
+ while ((entry = zipArchive.getNextEntry()) != null) {
+ String name = entry.getName();
+ if (name.endsWith("/")) {
+ continue;
+ }
+ callback.addFile(uri.resolve(name), zipArchive);
+ if (!addedClasses && name.startsWith("WEB-INF/classes/")) {
+ callback.addToClasspath(classes);
+ } else if (name.startsWith("WEB-INF/lib/")) {
+ if (name.indexOf('/', 12) == -1 && (name.endsWith(".jar") || name.endsWith(".zip"))) {
+ callback.addToClasspath(uri.resolve(name));
+ }
+ }
+ }
+ } catch (IOException e) {
+ throw new DeploymentException("Unable to unpack WAR content", e);
+ }
+ } else {
+ // copy directory into Configuration
+ try {
+ copyDir(callback, uri, moduleDirectory);
+ } catch (IOException e) {
+ throw new DeploymentException("Unable to copy archive directory", e);
+ }
+ }
+ }
+ private void copyDir(ConfigurationCallback callback, URI path, File dir) throws IOException {
+ assert dir.isDirectory();
+ File[] files = dir.listFiles();
+ boolean libDir = lib.equals(path);
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ if (file.isDirectory()) {
+ URI subURI = path.resolve(file.getName() + "/");
+ copyDir(callback, subURI, file);
+ if (classes.equals(subURI)) {
+ callback.addToClasspath(classes);
+ }
+ } else {
+ FileInputStream is = new FileInputStream(file);
+ try {
+ URI subURI = path.resolve(file.getName());
+ callback.addFile(subURI, is);
+ if (libDir && (file.getName().endsWith(".jar") || file.getName().endsWith(".jar"))) {
+ callback.addToClasspath(subURI);
+ }
+ } finally {
+ is.close();
+ }
}
- } catch (IOException e) {
- throw new DeploymentException("Unable to download WAR content", e);
}
}
+ public void complete() {
+ super.complete();
+ if (zipArchive != null && closeStream) {
+ try {
+ zipArchive.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
}
1.2 +8 -11 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/UnpackedModule.java
Index: UnpackedModule.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/UnpackedModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnpackedModule.java 24 Jan 2004 21:07:44 -0000 1.1
+++ UnpackedModule.java 26 Jan 2004 05:55:27 -0000 1.2
@@ -56,10 +56,10 @@
package org.apache.geronimo.jetty.deployment;
import java.io.File;
+import java.net.URI;
import org.apache.geronimo.deployment.util.XMLUtil;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
/**
*
@@ -67,17 +67,14 @@
* @version $Revision$ $Date$
*/
public class UnpackedModule extends AbstractModule {
- public UnpackedModule(File archive, Document doc) {
+ public UnpackedModule(URI configID, File archive, Document deploymentPlan) {
+ super(configID);
this.uri = archive.toURI();
- Element contextElement = XMLUtil.getChild(doc.getDocumentElement(), "context-root");
- if (contextElement == null) {
- contextPath = archive.getName();
- if (contextPath.endsWith(".war")) {
- contextPath = contextPath.substring(0, contextPath.length()-4);
- }
- } else {
- contextPath = (String) XMLUtil.getContent(contextElement);
+ contextPath = archive.getName();
+ if (contextPath.endsWith(".war")) {
+ contextPath = contextPath.substring(0, contextPath.length() - 4);
}
+ contextPath = XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", contextPath, contextPath);
}
}
1.4 +10 -6 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigurationFactory.java
Index: WARConfigurationFactory.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WARConfigurationFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WARConfigurationFactory.java 24 Jan 2004 21:07:44 -0000 1.3
+++ WARConfigurationFactory.java 26 Jan 2004 05:55:27 -0000 1.4
@@ -57,10 +57,10 @@
import java.io.File;
import java.io.InputStream;
+import java.net.URI;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.DeploymentConfiguration;
-import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
import org.apache.geronimo.deployment.DeploymentException;
@@ -84,22 +84,26 @@
return new WARConfiguration(deployable);
}
- public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(InputStream moduleArchive, Document deploymentPlan, URI configID) throws DeploymentException {
Element root = deploymentPlan.getDocumentElement();
if (!"web-app".equals(root.getNodeName())) {
return null;
}
- return new JettyModule(moduleArchive, deploymentPlan);
+ return new JettyModule(configID, moduleArchive, deploymentPlan);
}
- public DeploymentModule createModule(File moduleArchive, Document deploymentPlan) throws DeploymentException {
+ public DeploymentModule createModule(File moduleArchive, Document deploymentPlan, URI configID, boolean isLocal) throws DeploymentException {
Element root = deploymentPlan.getDocumentElement();
if (!"web-app".equals(root.getNodeName())) {
return null;
}
- return new UnpackedModule(moduleArchive, deploymentPlan);
+ if (isLocal && moduleArchive.isDirectory()) {
+ return new UnpackedModule(configID, moduleArchive, deploymentPlan);
+ } else {
+ return new JettyModule(configID, moduleArchive, deploymentPlan);
+ }
}
public static final GBeanInfo GBEAN_INFO;
1.3 +2 -1 incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
Index: ApplicationTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ApplicationTest.java 25 Jan 2004 21:07:04 -0000 1.2
+++ ApplicationTest.java 26 Jan 2004 05:55:27 -0000 1.3
@@ -95,6 +95,7 @@
app.setAttribute("ContextPath", "/test");
app.setAttribute("ComponentContext", null);
app.setAttribute("PolicyContextID", null);
+ app.setReferencePatterns("Configuration", Collections.EMPTY_SET);
app.setReferencePatterns("JettyContainer", containerPatterns);
app.setReferencePatterns("TransactionManager", Collections.EMPTY_SET);
app.setReferencePatterns("TrackedConnectionAssociator", Collections.EMPTY_SET);
1.3 +35 -13 incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/DeploymentTest.java
Index: DeploymentTest.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/DeploymentTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DeploymentTest.java 24 Jan 2004 21:07:45 -0000 1.2
+++ DeploymentTest.java 26 Jan 2004 05:55:27 -0000 1.3
@@ -90,8 +90,7 @@
private Target[] targets;
public void testUnpacked() throws Exception {
- URL url = classLoader.getResource("deployables/war1/");
- File war = new File(URI.create(url.toString()));
+ File war = new File(URI.create(classLoader.getResource("deployables/war1/").toString()));
ProgressObject result = manager.distribute(targets, war, new File(war, "WEB-INF/geronimo-web.xml"));
waitFor(result);
@@ -100,19 +99,38 @@
result = manager.start(ids);
waitFor(result);
+ checkHaveContent();
- HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678/test/hello.txt").openConnection();
- BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
- assertEquals("Hello World", reader.readLine());
- connection.disconnect();
+ result = manager.stop(ids);
+ waitFor(result);
+
+ checkNoContent();
+ }
+
+ public void testPacked() throws Exception {
+ File war1 = new File(URI.create(classLoader.getResource("deployables/war1/").toString()));
+ File war2 = new File(URI.create(classLoader.getResource("deployables/war2.war").toString()));
+
+ ProgressObject result = manager.distribute(targets, war2, new File(war1, "WEB-INF/geronimo-web.xml"));
+ waitFor(result);
+ TargetModuleID[] ids = result.getResultTargetModuleIDs();
+ assertEquals(1, ids.length);
+
+ result = manager.start(ids);
+ waitFor(result);
+ checkHaveContent();
result = manager.stop(ids);
waitFor(result);
+ checkNoContent();
+ }
+
+ private void checkNoContent() throws IOException {
+ HttpURLConnection connection;
connection = (HttpURLConnection) new URL("http://localhost:5678/test/hello.txt").openConnection();
try {
- reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ connection.getInputStream();
fail();
} catch (IOException e) {
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
@@ -120,6 +138,14 @@
connection.disconnect();
}
+ private void checkHaveContent() throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678/test/hello.txt").openConnection();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertEquals("Hello World", reader.readLine());
+ connection.disconnect();
+ }
+
private void waitFor(ProgressObject result) throws InterruptedException {
result.addProgressListener(new ProgressListener() {
public void handleProgressEvent(ProgressEvent event) {
@@ -135,10 +161,6 @@
}
assertEquals(StateType.COMPLETED, result.getDeploymentStatus().getState());
}
-
-// public void testPacked() throws Exception {
-// manager.distribute(targets, war.openStream(), new ByteArrayInputStream(plan));
-// }
protected void setUp() throws Exception {
super.setUp();
1.11 +5 -5 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Index: Kernel.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Kernel.java 24 Jan 2004 21:07:45 -0000 1.10
+++ Kernel.java 26 Jan 2004 05:55:27 -0000 1.11
@@ -165,6 +165,10 @@
return mbServer;
}
+ public static ObjectName getConfigObjectName(URI configID) throws MalformedObjectNameException {
+ return new ObjectName("geronimo.config:name=" + ObjectName.quote(configID.toString()));
+ }
+
/**
* Install the CAR at the supplied URL into this kernel's store
* @param source the URL of a CAR format archive
@@ -222,10 +226,6 @@
}
load(config, rootURL, configName);
return configName;
- }
-
- public ObjectName getConfigObjectName(URI configID) throws MalformedObjectNameException {
- return new ObjectName("geronimo.config:name=" + ObjectName.quote(configID.toString()));
}
/**
1.2 +5 -1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java
Index: ConfigurationParent.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationParent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationParent.java 12 Jan 2004 01:39:46 -0000 1.1
+++ ConfigurationParent.java 26 Jan 2004 05:55:27 -0000 1.2
@@ -55,6 +55,8 @@
*/
package org.apache.geronimo.kernel.config;
+import java.net.URL;
+
/**
*
*
@@ -62,4 +64,6 @@
*/
public interface ConfigurationParent {
ClassLoader getClassLoader();
+
+ URL getBaseURL();
}