You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ad...@apache.org on 2004/12/31 15:35:41 UTC
svn commit: r123795 - in geronimo/trunk/modules/tomcat/src: java/org/apache/geronimo/tomcat java/org/apache/geronimo/tomcat/deployment test/org/apache/geronimo/tomcat
Author: adc
Date: Fri Dec 31 06:35:40 2004
New Revision: 123795
URL: http://svn.apache.org/viewcvs?view=rev&rev=123795
Log:
Removed the TomcatSecureWebAppContext and placed code in TomcatWebAppContext
http://issues.apache.org/jira/browse/GERONIMO-533
Removed:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java
Modified:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Deleted: /geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatSecureWebAppContext.java?view=auto&rev=123794
==============================================================================
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?view=diff&rev=123795&p1=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java&r1=123794&p2=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java&r2=123795
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java Fri Dec 31 06:35:40 2004
@@ -21,6 +21,9 @@
import java.net.URL;
import org.apache.catalina.Context;
+import org.apache.catalina.Realm;
+import org.apache.catalina.deploy.SecurityConstraint;
+import org.apache.catalina.deploy.LoginConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,8 +52,19 @@
private String docBase = null;
- public TomcatWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl, TomcatContainer container) {
+ private final LoginConfig loginConfig;
+ private final Realm tomcatRealm;
+
+ private final SecurityConstraint[] securityConstraints;
+
+ private final String[] securityRoles;
+
+
+ public TomcatWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl, String authMethod,
+ String realmName, String loginPage, String errorPage, Realm tomcatRealm,
+ SecurityConstraint[] securityConstraints, String[] securityRoles,
+ TomcatContainer container) {
assert webAppRoot != null;
assert webClassPath != null;
assert configurationBaseUrl != null;
@@ -60,6 +74,19 @@
this.container = container;
this.setDocBase(this.webAppRoot.getPath());
+ this.tomcatRealm = tomcatRealm;
+ this.securityConstraints = securityConstraints;
+ this.securityRoles = securityRoles;
+
+ if (authMethod != null){
+ loginConfig = new LoginConfig();
+ loginConfig.setAuthMethod(authMethod);
+ loginConfig.setRealmName(realmName);
+ loginConfig.setLoginPage(loginPage);
+ loginConfig.setErrorPage(errorPage);
+ } else {
+ loginConfig = null;
+ }
}
public String getDocBase() {
@@ -73,6 +100,28 @@
public void setContextProperties() {
context.setDocBase(webAppRoot.getPath());
context.setPath(path);
+
+ //Security
+ if (tomcatRealm != null)
+ context.setRealm(tomcatRealm);
+
+ if (loginConfig != null)
+ context.setLoginConfig(loginConfig);
+
+ // Add the security constraints
+ if (securityConstraints != null) {
+ for (int i = 0; i < securityConstraints.length; i++) {
+ SecurityConstraint sc = securityConstraints[i];
+ context.addConstraint(sc);
+ }
+ }
+
+ // Add the security roles
+ if (securityRoles != null) {
+ for (int i = 0; i < securityRoles.length; i++) {
+ context.addSecurityRole(securityRoles[i]);
+ }
+ }
}
public Context getContext() {
@@ -109,7 +158,7 @@
public void doFail() {
container.removeContext(this);
-
+
log.info("TomcatWebAppContext failed");
}
@@ -124,9 +173,20 @@
infoFactory.addAttribute("path", String.class, true);
+ infoFactory.addAttribute("authMethod", String.class, true);
+ infoFactory.addAttribute("realmName", String.class, true);
+ infoFactory.addAttribute("loginPage", String.class, true);
+ infoFactory.addAttribute("errorPage", String.class, true);
+
+ infoFactory.addAttribute("tomcatRealm", Realm.class, true);
+ infoFactory.addAttribute("securityConstraints", SecurityConstraint[].class, true);
+ infoFactory.addAttribute("securityRoles", String[].class, true);
+
infoFactory.addReference("Container", TomcatContainer.class);
- infoFactory.setConstructor(new String[]{"webAppRoot", "webClassPath", "configurationBaseUrl", "Container"});
+ infoFactory.setConstructor(new String[]{"webAppRoot", "webClassPath", "configurationBaseUrl", "authMethod",
+ "realmName", "loginPage", "errorPage", "tomcatRealm",
+ "securityConstraints", "securityRoles", "Container"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java?view=diff&rev=123795&p1=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java&r1=123794&p2=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java&r2=123795
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java Fri Dec 31 06:35:40 2004
@@ -1,337 +1,341 @@
-/**
- *
- * Copyright 2003-2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.geronimo.tomcat.deployment;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.deployment.util.DeploymentUtil;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.jmx.GBeanMBean;
-import org.apache.geronimo.j2ee.deployment.EARContext;
-import org.apache.geronimo.j2ee.deployment.Module;
-import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
-import org.apache.geronimo.j2ee.deployment.WebModule;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
-import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
-import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.schema.SchemaConversionUtils;
-import org.apache.geronimo.tomcat.TomcatWebAppContext;
-import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
-import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
-import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
-import org.apache.geronimo.xbeans.j2ee.WebAppType;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-
-/**
- * @version $Rev: 106522 $ $Date: 2004-11-25 01:28:57 +0100 (Thu, 25 Nov 2004) $
- */
-public class TomcatModuleBuilder implements ModuleBuilder {
-
- private final URI defaultParentId;
-
- private static final Log log = LogFactory.getLog(TomcatModuleBuilder.class);
-
- public TomcatModuleBuilder(URI defaultParentId) {
- log.debug("TomcatModuleBuilder(" + defaultParentId + ")");
-
- this.defaultParentId = defaultParentId;
- }
-
- public String addGBeans(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
- J2eeContext earJ2eeContext = earContext.getJ2eeContext();
- J2eeContext moduleJ2eeContext = new J2eeContextImpl(earJ2eeContext.getJ2eeDomainName(), earJ2eeContext
- .getJ2eeServerName(), earJ2eeContext.getJ2eeApplicationName(), module.getName(), null, null);
- WebModule webModule = (WebModule) module;
-
- // construct the webClassLoader
- URI[] webClassPath = getWebClassPath(earContext, webModule);
- URI baseUri = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/")).toURI();
- URL[] webClassPathURLs = new URL[webClassPath.length];
- for (int i = 0; i < webClassPath.length; i++) {
- URI path = baseUri.resolve(webClassPath[i]);
- try {
- webClassPathURLs[i] = path.toURL();
- } catch (MalformedURLException e) {
- throw new DeploymentException("Invalid web class path element: path=" + path + ", baseUri=" + baseUri);
- }
- }
-
- ObjectName webModuleName = null;
- try {
- webModuleName = NameFactory
- .getModuleName(null, null, null, null, NameFactory.WEB_MODULE, moduleJ2eeContext);
- } catch (MalformedObjectNameException e) {
- throw new DeploymentException("Could not construct module name", e);
- }
-
- GBeanMBean gbean;
- try {
- gbean = new GBeanMBean(TomcatWebAppContext.GBEAN_INFO);
-
- gbean.setAttribute("webAppRoot", baseUri);
- gbean.setAttribute("webClassPath", webClassPath);
-
- gbean.setAttribute("path", webModule.getContextRoot());
-
- gbean.setReferencePattern("Container", new ObjectName("*:type=WebContainer,container=Tomcat"));
- } catch (Exception e) {
- throw new DeploymentException("Unable to initialize webapp GBean", e);
- }
- earContext.addGBean(webModuleName, gbean);
- return null;
- }
-
- public Module createModule(File plan, JarFile moduleFile) throws DeploymentException {
- log.debug("createModule: " + plan + "; " + moduleFile);
-
- // parse the spec dd
- String specDD;
- WebAppType webApp;
- try {
- specDD = DeploymentUtil.readAll(DeploymentUtil.createJarURL(moduleFile, "WEB-INF/web.xml"));
-
- // parse it
- XmlObject parsed = SchemaConversionUtils.parse(specDD);
- WebAppDocument webAppDoc = SchemaConversionUtils.convertToServletSchema(parsed);
- webApp = webAppDoc.getWebApp();
- } catch (XmlException xmle) {
- throw new DeploymentException("Error parsing web.xml", xmle);
- } catch (Exception e) {
- return null;
- }
-
- // parse vendor dd
- JettyWebAppType jettyWebApp = getJettyWebApp(plan, moduleFile, false, "war", webApp);
-
- // get the ids from either the application plan or for a stand alone
- // module from the specific deployer
- URI configId = null;
- try {
- configId = new URI(jettyWebApp.getConfigId());
- } catch (URISyntaxException e) {
- throw new DeploymentException("Invalid configId " + jettyWebApp.getConfigId(), e);
- }
-
- URI parentId = null;
- if (jettyWebApp.isSetParentId()) {
- try {
- parentId = new URI(jettyWebApp.getParentId());
- } catch (URISyntaxException e) {
- throw new DeploymentException("Invalid parentId " + jettyWebApp.getParentId(), e);
- }
- } else {
- parentId = defaultParentId;
- }
-
- // for now, every webapps will get defaultParentId which is
- // org/apache/geronimo/Tomcat
- // TODO: Create a general WebModuleBuilder and hand over deploying a
- // webapp to Jetty- or TomcatModuleBuilder based on parentId.
- log.warn("Assigning defaultParentId [" + defaultParentId + "] to webapp [" + configId + "]");
- parentId = defaultParentId;
-
- WebModule module = new WebModule(false, configId, parentId, moduleFile, "war", webApp, jettyWebApp, specDD);
- module.setContextRoot(jettyWebApp.getContextRoot());
-
- return module;
- }
-
- public Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, URI earConfigId)
- throws DeploymentException {
- log.debug("createModule: " + plan + "; " + moduleFile + "; " + targetPath + "; " + specDDUrl + "; "
- + earConfigId);
- return null;
- }
-
- /**
- * What's the difference between this and createModule - the params are the
- * same
- */
- public void initContext(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
- log.debug("initContext: " + earContext + "; " + module + "; " + cl);
- }
-
- public void installModule(JarFile earFile, EARContext earContext, Module module) throws DeploymentException {
- log.debug("installModule: " + earFile + "; " + earContext + "; " + module);
- try {
- URI baseDir = URI.create(module.getTargetPath() + "/");
-
- // add the warfile's content to the configuration
- JarFile warFile = module.getModuleFile();
- Enumeration entries = warFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- URI targetPath = baseDir.resolve(entry.getName());
- /*
- * if (entry.getName().equals("WEB-INF/web.xml")) {
- * earContext.addFile(targetPath, module.getOriginalSpecDD()); }
- * else { earContext.addFile(targetPath, warFile, entry); }
- */
- earContext.addFile(targetPath, warFile, entry);
- }
-
- // add the manifest classpath entries declared in the war to the
- // class loader
- // we have to explicitly add these since we are unpacking the web
- // module
- // and the url class loader will not pick up a manifiest from an
- // unpacked dir
- earContext.addManifestClassPath(warFile, URI.create(module.getTargetPath()));
-
- } catch (IOException e) {
- throw new DeploymentException("Problem deploying war", e);
- }
- }
-
- JettyWebAppType getJettyWebApp(Object plan, JarFile moduleFile, boolean standAlone, String targetPath,
- WebAppType webApp) throws DeploymentException {
- JettyWebAppType jettyWebApp = null;
- try {
- // load the geronimo-jetty.xml from either the supplied plan or from
- // the earFile
- try {
- if (plan instanceof XmlObject) {
- jettyWebApp = (JettyWebAppType) SchemaConversionUtils.getNestedObjectAsType((XmlObject) plan,
- "web-app", JettyWebAppType.type);
- } else {
- JettyWebAppDocument jettyWebAppdoc = null;
- if (plan != null) {
- jettyWebAppdoc = JettyWebAppDocument.Factory.parse((File) plan);
- } else {
- URL path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-jetty.xml");
- jettyWebAppdoc = JettyWebAppDocument.Factory.parse(path);
- }
- if (jettyWebAppdoc != null) {
- jettyWebApp = jettyWebAppdoc.getWebApp();
- }
- }
- } catch (IOException e) {
- }
-
- // if we got one extract and validate it otherwise create a default
- // one
- if (jettyWebApp != null) {
- jettyWebApp = (JettyWebAppType) SchemaConversionUtils.convertToGeronimoNamingSchema(jettyWebApp);
- jettyWebApp = (JettyWebAppType) SchemaConversionUtils.convertToGeronimoSecuritySchema(jettyWebApp);
- SchemaConversionUtils.validateDD(jettyWebApp);
- } else {
- String path;
- if (standAlone) {
- // default configId is based on the moduleFile name
- path = new File(moduleFile.getName()).getName();
- } else {
- // default configId is based on the module uri from the
- // application.xml
- path = targetPath;
- }
- jettyWebApp = createDefaultPlan(path, webApp);
- }
- } catch (XmlException e) {
- throw new DeploymentException("xml problem", e);
- }
- return jettyWebApp;
- }
-
- private JettyWebAppType createDefaultPlan(String path, WebAppType webApp) {
- String id = webApp.getId();
- if (id == null) {
- id = path;
- if (id.endsWith(".war")) {
- id = id.substring(0, id.length() - 4);
- }
- if (id.endsWith("/")) {
- id = id.substring(0, id.length() - 1);
- }
- }
-
- JettyWebAppType jettyWebApp = JettyWebAppType.Factory.newInstance();
-
- // set the parentId, configId and context root
- jettyWebApp.setParentId(defaultParentId.toString());
- if (null != webApp.getId()) {
- id = webApp.getId();
- }
- jettyWebApp.setConfigId(id);
- jettyWebApp.setContextRoot(id);
- return jettyWebApp;
- }
-
- private static URI[] getWebClassPath(EARContext earContext, WebModule webModule) {
- LinkedList webClassPath = new LinkedList();
- File baseDir = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/"));
- File webInfDir = new File(baseDir, "WEB-INF");
-
- // check for a classes dir
- File classesDir = new File(webInfDir, "classes");
- if (classesDir.isDirectory()) {
- webClassPath.add(URI.create("WEB-INF/classes/"));
- }
-
- // add all of the libs
- File libDir = new File(webInfDir, "lib");
- if (libDir.isDirectory()) {
- File[] libs = libDir.listFiles(new FileFilter() {
- public boolean accept(File file) {
- return file.isFile() && file.getName().endsWith(".jar");
- }
- });
-
- if (libs != null) {
- for (int i = 0; i < libs.length; i++) {
- File lib = libs[i];
- webClassPath.add(URI.create("WEB-INF/lib/" + lib.getName()));
- }
- }
- }
- return (URI[]) webClassPath.toArray(new URI[webClassPath.size()]);
- }
-
- public static final GBeanInfo GBEAN_INFO;
-
- static {
- GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(TomcatModuleBuilder.class);
- infoBuilder.addAttribute("defaultParentId", URI.class, true);
- infoBuilder.addInterface(ModuleBuilder.class);
-
- infoBuilder.setConstructor(new String[] { "defaultParentId" });
-
- GBEAN_INFO = infoBuilder.getBeanInfo();
- }
-
- public static GBeanInfo getGBeanInfo() {
- return GBEAN_INFO;
- }
-}
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.tomcat.deployment;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.deployment.EARContext;
+import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
+import org.apache.geronimo.j2ee.deployment.WebModule;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.geronimo.tomcat.TomcatWebAppContext;
+import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
+import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
+import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
+import org.apache.geronimo.xbeans.j2ee.WebAppType;
+
+
+/**
+ * @version $Rev: 106522 $ $Date: 2004-11-25 01:28:57 +0100 (Thu, 25 Nov 2004) $
+ */
+public class TomcatModuleBuilder implements ModuleBuilder {
+
+ private final URI defaultParentId;
+
+ private static final Log log = LogFactory.getLog(TomcatModuleBuilder.class);
+
+ public TomcatModuleBuilder(URI defaultParentId) {
+ log.debug("TomcatModuleBuilder(" + defaultParentId + ")");
+
+ this.defaultParentId = defaultParentId;
+ }
+
+ public String addGBeans(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
+ J2eeContext earJ2eeContext = earContext.getJ2eeContext();
+ J2eeContext moduleJ2eeContext = new J2eeContextImpl(earJ2eeContext.getJ2eeDomainName(),
+ earJ2eeContext.getJ2eeServerName(),
+ earJ2eeContext.getJ2eeApplicationName(),
+ module.getName(), null, null);
+ WebModule webModule = (WebModule) module;
+
+ // construct the webClassLoader
+ URI[] webClassPath = getWebClassPath(earContext, webModule);
+ URI baseUri = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/")).toURI();
+ URL[] webClassPathURLs = new URL[webClassPath.length];
+ for (int i = 0; i < webClassPath.length; i++) {
+ URI path = baseUri.resolve(webClassPath[i]);
+ try {
+ webClassPathURLs[i] = path.toURL();
+ } catch (MalformedURLException e) {
+ throw new DeploymentException("Invalid web class path element: path=" + path + ", baseUri=" + baseUri);
+ }
+ }
+
+ ObjectName webModuleName = null;
+ try {
+ webModuleName = NameFactory.getModuleName(null, null, null, null, NameFactory.WEB_MODULE, moduleJ2eeContext);
+ } catch (MalformedObjectNameException e) {
+ throw new DeploymentException("Could not construct module name", e);
+ }
+
+ GBeanData gbean;
+ try {
+ gbean = new GBeanData(TomcatWebAppContext.GBEAN_INFO);
+
+ gbean.setName(webModuleName);
+ gbean.setAttribute("webAppRoot", baseUri);
+ gbean.setAttribute("webClassPath", webClassPath);
+
+ gbean.setAttribute("path", webModule.getContextRoot());
+
+ gbean.setReferencePattern("Container", new ObjectName("*:type=WebContainer,container=Tomcat"));
+ } catch (Exception e) {
+ throw new DeploymentException("Unable to initialize webapp GBean", e);
+ }
+ earContext.addGBean(gbean);
+
+ return null;
+ }
+
+ public Module createModule(File plan, JarFile moduleFile) throws DeploymentException {
+ log.debug("createModule: " + plan + "; " + moduleFile);
+
+ // parse the spec dd
+ String specDD;
+ WebAppType webApp;
+ try {
+ specDD = DeploymentUtil.readAll(DeploymentUtil.createJarURL(moduleFile, "WEB-INF/web.xml"));
+
+ // parse it
+ XmlObject parsed = SchemaConversionUtils.parse(specDD);
+ WebAppDocument webAppDoc = SchemaConversionUtils.convertToServletSchema(parsed);
+ webApp = webAppDoc.getWebApp();
+ } catch (XmlException xmle) {
+ throw new DeploymentException("Error parsing web.xml", xmle);
+ } catch (Exception e) {
+ return null;
+ }
+
+ // parse vendor dd
+ JettyWebAppType jettyWebApp = getJettyWebApp(plan, moduleFile, false, "war", webApp);
+
+ // get the ids from either the application plan or for a stand alone
+ // module from the specific deployer
+ URI configId = null;
+ try {
+ configId = new URI(jettyWebApp.getConfigId());
+ } catch (URISyntaxException e) {
+ throw new DeploymentException("Invalid configId " + jettyWebApp.getConfigId(), e);
+ }
+
+ URI parentId = null;
+ if (jettyWebApp.isSetParentId()) {
+ try {
+ parentId = new URI(jettyWebApp.getParentId());
+ } catch (URISyntaxException e) {
+ throw new DeploymentException("Invalid parentId " + jettyWebApp.getParentId(), e);
+ }
+ } else {
+ parentId = defaultParentId;
+ }
+
+ // for now, every webapps will get defaultParentId which is
+ // org/apache/geronimo/Tomcat
+ // TODO: Create a general WebModuleBuilder and hand over deploying a
+ // webapp to Jetty- or TomcatModuleBuilder based on parentId.
+ log.warn("Assigning defaultParentId [" + defaultParentId + "] to webapp [" + configId + "]");
+ parentId = defaultParentId;
+
+ WebModule module = new WebModule(false, configId, parentId, moduleFile, "war", webApp, jettyWebApp, specDD);
+ module.setContextRoot(jettyWebApp.getContextRoot());
+
+ return module;
+ }
+
+ public Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, URI earConfigId)
+ throws DeploymentException {
+ log.debug("createModule: " + plan + "; " + moduleFile + "; " + targetPath + "; " + specDDUrl + "; "
+ + earConfigId);
+ return null;
+ }
+
+ /**
+ * What's the difference between this and createModule - the params are the
+ * same
+ */
+ public void initContext(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException {
+ log.debug("initContext: " + earContext + "; " + module + "; " + cl);
+ }
+
+ public void installModule(JarFile earFile, EARContext earContext, Module module) throws DeploymentException {
+ log.debug("installModule: " + earFile + "; " + earContext + "; " + module);
+ try {
+ URI baseDir = URI.create(module.getTargetPath() + "/");
+
+ // add the warfile's content to the configuration
+ JarFile warFile = module.getModuleFile();
+ Enumeration entries = warFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ URI targetPath = baseDir.resolve(entry.getName());
+ /*
+ * if (entry.getName().equals("WEB-INF/web.xml")) {
+ * earContext.addFile(targetPath, module.getOriginalSpecDD()); }
+ * else { earContext.addFile(targetPath, warFile, entry); }
+ */
+ earContext.addFile(targetPath, warFile, entry);
+ }
+
+ // add the manifest classpath entries declared in the war to the
+ // class loader
+ // we have to explicitly add these since we are unpacking the web
+ // module
+ // and the url class loader will not pick up a manifiest from an
+ // unpacked dir
+ earContext.addManifestClassPath(warFile, URI.create(module.getTargetPath()));
+
+ } catch (IOException e) {
+ throw new DeploymentException("Problem deploying war", e);
+ }
+ }
+
+ JettyWebAppType getJettyWebApp(Object plan, JarFile moduleFile, boolean standAlone, String targetPath,
+ WebAppType webApp) throws DeploymentException {
+ JettyWebAppType jettyWebApp = null;
+ try {
+ // load the geronimo-jetty.xml from either the supplied plan or from
+ // the earFile
+ try {
+ if (plan instanceof XmlObject) {
+ jettyWebApp = (JettyWebAppType) SchemaConversionUtils.getNestedObjectAsType((XmlObject) plan,
+ "web-app", JettyWebAppType.type);
+ } else {
+ JettyWebAppDocument jettyWebAppdoc = null;
+ if (plan != null) {
+ jettyWebAppdoc = JettyWebAppDocument.Factory.parse((File) plan);
+ } else {
+ URL path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-jetty.xml");
+ jettyWebAppdoc = JettyWebAppDocument.Factory.parse(path);
+ }
+ if (jettyWebAppdoc != null) {
+ jettyWebApp = jettyWebAppdoc.getWebApp();
+ }
+ }
+ } catch (IOException e) {
+ }
+
+ // if we got one extract and validate it otherwise create a default
+ // one
+ if (jettyWebApp != null) {
+ jettyWebApp = (JettyWebAppType) SchemaConversionUtils.convertToGeronimoNamingSchema(jettyWebApp);
+ jettyWebApp = (JettyWebAppType) SchemaConversionUtils.convertToGeronimoSecuritySchema(jettyWebApp);
+ SchemaConversionUtils.validateDD(jettyWebApp);
+ } else {
+ String path;
+ if (standAlone) {
+ // default configId is based on the moduleFile name
+ path = new File(moduleFile.getName()).getName();
+ } else {
+ // default configId is based on the module uri from the
+ // application.xml
+ path = targetPath;
+ }
+ jettyWebApp = createDefaultPlan(path, webApp);
+ }
+ } catch (XmlException e) {
+ throw new DeploymentException("xml problem", e);
+ }
+ return jettyWebApp;
+ }
+
+ private JettyWebAppType createDefaultPlan(String path, WebAppType webApp) {
+ String id = webApp.getId();
+ if (id == null) {
+ id = path;
+ if (id.endsWith(".war")) {
+ id = id.substring(0, id.length() - 4);
+ }
+ if (id.endsWith("/")) {
+ id = id.substring(0, id.length() - 1);
+ }
+ }
+
+ JettyWebAppType jettyWebApp = JettyWebAppType.Factory.newInstance();
+
+ // set the parentId, configId and context root
+ jettyWebApp.setParentId(defaultParentId.toString());
+ if (null != webApp.getId()) {
+ id = webApp.getId();
+ }
+ jettyWebApp.setConfigId(id);
+ jettyWebApp.setContextRoot(id);
+ return jettyWebApp;
+ }
+
+ private static URI[] getWebClassPath(EARContext earContext, WebModule webModule) {
+ LinkedList webClassPath = new LinkedList();
+ File baseDir = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/"));
+ File webInfDir = new File(baseDir, "WEB-INF");
+
+ // check for a classes dir
+ File classesDir = new File(webInfDir, "classes");
+ if (classesDir.isDirectory()) {
+ webClassPath.add(URI.create("WEB-INF/classes/"));
+ }
+
+ // add all of the libs
+ File libDir = new File(webInfDir, "lib");
+ if (libDir.isDirectory()) {
+ File[] libs = libDir.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isFile() && file.getName().endsWith(".jar");
+ }
+ });
+
+ if (libs != null) {
+ for (int i = 0; i < libs.length; i++) {
+ File lib = libs[i];
+ webClassPath.add(URI.create("WEB-INF/lib/" + lib.getName()));
+ }
+ }
+ }
+ return (URI[]) webClassPath.toArray(new URI[webClassPath.size()]);
+ }
+
+ public static final GBeanInfo GBEAN_INFO;
+
+ static {
+ GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(TomcatModuleBuilder.class);
+ infoBuilder.addAttribute("defaultParentId", URI.class, true);
+ infoBuilder.addInterface(ModuleBuilder.class);
+
+ infoBuilder.setConstructor(new String[]{"defaultParentId"});
+
+ GBEAN_INFO = infoBuilder.getBeanInfo();
+ }
+
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
+ }
+}
Modified: geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?view=diff&rev=123795&p1=geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java&r1=123794&p2=geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java&r2=123795
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (original)
+++ geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java Fri Dec 31 06:35:40 2004
@@ -132,7 +132,7 @@
// securityRoles, Map legacySecurityConstraintMap) throws Exception {
protected ObjectName setUpSecureAppContext(SecurityConstraint[] securityConstraints, String[] securityRoles)
throws Exception {
- GBeanData app = new GBeanData(webModuleName, TomcatSecureWebAppContext.GBEAN_INFO);
+ GBeanData app = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
app.setAttribute("webAppRoot", new File("target/var/catalina/webapps/war3/").toURI());
app.setAttribute("webClassPath", new URI[] {});
app.setAttribute("configurationBaseUrl", new File("target/var/catalina/webapps/war3/WEB-INF/web.xml").toURL());