geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacek Laskowski <jlaskow...@apache.org>
Subject Re: svn commit: r109826 - in geronimo/trunk/modules: assembly assembly/src/plan tomcat tomcat/src/java/org/apache/geronimo/tomcat tomcat/src/java/org/apache/geronimo/tomcat/deployment tomcat/src/plan
Date Sat, 04 Dec 2004 21:40:19 GMT
Hi,

Just to rise your attention to the changes to the Apache Tomcat gbean.

Please, update your local copy of Geronimo sources and build it. That 
will prove I haven't broken the assembly module (I don't really want to 
introduce any issues with Geronimo build). Make the changes described 
below and give it a try - report your findings back to the mailing list.

What bothers me much is that it's not yet possible to run the deployed 
webapps. There's the misterious error message: 'Error getConfigured' 
(see org/apache/catalina/core/StandardContext:4036) which I don't 
understand, thus I'm stuck. I'll write about it to the Tomcat dev 
mailing list.

Jacek

jlaskowski@apache.org wrote:
> Author: jlaskowski
> Date: Sat Dec  4 13:09:00 2004
> New Revision: 109826
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=109826
> Log:
> The first attempt to create a builder for Apache Tomcat.   
> It breaks the way Apache Tomcat have been embedded into Geronimo, which means
> no webapps directory is supported. Unfortunatelly, it doesn't work yet, so although
> some webapps can be deployed using the builder they may not run due to missing jars or
classes.
> 
> To give it a try uncomment the marked sections in the assembly module's files:
> 
>  o modules/assembly/project.xml
>  o modules/assembly/src/plan/j2ee-server-plan.xml
>  o modules/assembly/src/plan/j2ee-deployer-plan.xml
> 
> and build Geronimo again (actually, the changes require to build assembly module only).
> 
> Hopefully, it won't break the assembly module.
> 
> TODO:
>  o Handle classloading for deployed webapps (see TomcatWebAppContext class)
>  o Introduce WEB-INF/geronimo-tomcat.xml where Geronimo-specific configuration will be
made
>  o Generate valid context root (now it's a random string; see TomcatModuleBuilder class)
> 
> NOTE: Currently, the context root of a deployed webapp is generated using System.currentTimeMillis
> and as such it will be visible in your browser
> 
> NOTE: I don't know why but webapps can't be correctly started up. The mysterious 'Error
getConfigured' shows up
> (see org/apache/catalina/core/StandardContext:4036). It doesn't only show up while starting
up in Geronimo - 
> I couldn't get it run as a standalone app. Any ideas?
> 
> 
> Added:
>    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
  (contents, props changed)
>    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/
>    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
  (contents, props changed)
> Modified:
>    geronimo/trunk/modules/assembly/project.xml
>    geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml
>    geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml
>    geronimo/trunk/modules/tomcat/maven.xml
>    geronimo/trunk/modules/tomcat/project.xml
>    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
>    geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml
> 
> Modified: geronimo/trunk/modules/assembly/project.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/project.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/assembly/project.xml&r1=109825&p2=geronimo/trunk/modules/assembly/project.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/assembly/project.xml	(original)
> +++ geronimo/trunk/modules/assembly/project.xml	Sat Dec  4 13:09:00 2004
> @@ -183,6 +183,15 @@
>  
>          <dependency>
>              <groupId>geronimo</groupId>
> +            <artifactId>geronimo-tomcat</artifactId>
> +            <version>${pom.currentVersion}</version>
> +            <properties>
> +                <repository>true</repository>
> +            </properties>
> +        </dependency>
> +
> +        <dependency>
> +            <groupId>geronimo</groupId>
>              <artifactId>geronimo-jetty-builder</artifactId>
>              <version>${pom.currentVersion}</version>
>              <properties>
> @@ -690,6 +699,17 @@
>              <groupId>jetty</groupId>
>              <artifactId>org.mortbay.jetty</artifactId>
>              <version>&jetty-version;</version>
> +            <properties>
> +                <repository>true</repository>
> +            </properties>
> +        </dependency>
> +        <dependency>
> +            <groupId>tomcat</groupId>
> +            <artifactId>catalina</artifactId>
> +            <!-- Don't want to break the other modules that rely on the libs -->
> +            <!--version>&tomcat-version;</version-->
> +            <version>5.5.4</version>
> +            <url>http://jakarta.apache.org/tomcat/</url>
>              <properties>
>                  <repository>true</repository>
>              </properties>
> 
> Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml&r1=109825&p2=geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml	(original)
> +++ geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml	Sat Dec  4 13:09:00
2004
> @@ -83,6 +83,22 @@
>      <dependency>
>          <uri>geronimo/jars/geronimo-jetty-${geronimo_version}.jar</uri>
>      </dependency>
> +    <!--
> +       - Uncomment it to run Apache Tomcat
> +       -
> +    <dependency>
> +        <uri>geronimo/jars/geronimo-tomcat-${geronimo_version}.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/catalina-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/naming-resources-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/tomcat-util-5.5.4.jar</uri>
> +    </dependency>
> +    -->
>      <dependency>
>          <uri>geronimo/jars/geronimo-naming-${geronimo_version}.jar</uri>
>      </dependency>
> @@ -143,6 +159,11 @@
>          <attribute name="defaultParentId">org/apache/geronimo/Server</attribute>
>          <!-- reference name="SecurityService">geronimo.security:type=SecurityService</reference
-->
>      </gbean>
> +    <!--
> +       - Uncomment it to run Apache Tomcat module builder
> +       -
> +    <gbean name="geronimo.deployer:role=ModuleBuilder,type=Web,config=org/apache/geronimo/J2EEDeployer"
class="org.apache.geronimo.tomcat.deployment.TomcatModuleBuilder"/>
> +    -->
>  
>      <gbean name="geronimo.deployer:role=ModuleBuilder,type=EJB,config=org/apache/geronimo/J2EEDeployer"
class="org.openejb.deployment.OpenEJBModuleBuilder">
>          <attribute name="defaultParentId">org/apache/geronimo/Server</attribute>
> 
> Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml&r1=109825&p2=geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml	(original)
> +++ geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml	Sat Dec  4 13:09:00
2004
> @@ -71,6 +71,61 @@
>      <dependency>
>          <uri>geronimo/jars/geronimo-jetty-${geronimo_version}.jar</uri>
>      </dependency>
> +    <!--
> +       - Uncomment it to run Apache Tomcat as the web container
> +       -
> +    <dependency>
> +        <uri>geronimo/jars/geronimo-tomcat-${geronimo_version}.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/catalina-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/jasper-compiler-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/jasper-runtime-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/tomcat-coyote-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/tomcat-http-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/tomcat-util-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/naming-resources-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/servlets-default-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>tomcat/jars/servlets-invoker-5.5.4.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>commons-beanutils/jars/commons-beanutils-1.6.1.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>commons-collections/jars/commons-collections-2.1.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>commons-digester/jars/commons-digester-1.6.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>commons-el/jars/commons-el-1.0.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>commons-modeler/jars/commons-modeler-1.1.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>regexp/jars/regexp-1.3.jar</uri>
> +    </dependency>
> +    <dependency>
> +        <uri>mx4j/jars/mx4j-2.0.1.jar</uri>
> +    </dependency>
> +    -->
>      <dependency>
>          <uri>geronimo/jars/geronimo-jmxremoting-${geronimo_version}.jar</uri>
>      </dependency>
> @@ -197,6 +252,11 @@
>  
>      <!-- default WAR container using Jetty -->
>      <gbean name="geronimo.server:type=WebContainer,container=Jetty" class="org.apache.geronimo.jetty.JettyContainerImpl"/>
> +    <!--
> +       - Uncomment it and comment the above Jetty GBean to run Apache Tomcat as the
web container
> +       -
> +    <gbean name="geronimo.server:type=WebContainer,container=Tomcat" class="org.apache.geronimo.tomcat.TomcatContainer"/>
> +    -->
>      <gbean name="geronimo.server:type=RequestLog,container=Jetty" class="org.apache.geronimo.jetty.requestlog.NCSARequestLog">
>          <reference name="JettyContainer">geronimo.server:type=WebContainer,container=Jetty</reference>
>          <reference name="ServerInfo">geronimo.system:role=ServerInfo</reference>
> 
> Modified: geronimo/trunk/modules/tomcat/maven.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/maven.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/tomcat/maven.xml&r1=109825&p2=geronimo/trunk/modules/tomcat/maven.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/tomcat/maven.xml	(original)
> +++ geronimo/trunk/modules/tomcat/maven.xml	Sat Dec  4 13:09:00 2004
> @@ -79,12 +79,7 @@
>  		<copy todir="../assembly/target/geronimo-${pom.currentVersion}/repository/mx4j/jars"
>  		      file="${maven.repo.local}/mx4j/jars/mx4j-&mx4j-version;.jar"/>
>          
> -        <copy todir="${geronimoHome}/var/catalina/conf" file="src/var/server.xml"/>
>          <copy todir="${geronimoHome}/var/catalina/conf" file="src/var/web.xml"/>
> -        
> -        <j:set var="tomcatWebappDir" value="${geronimoHome}/var/catalina/webapps"/>
> -        <echo>Deploy your webapps to ${tomcatWebappDir}</echo>
> -		<mkdir dir="${tomcatWebappDir}"/>
>          
>          <echo>Deploying Apache Tomcat configuration</echo>
>          <java fork="true" jar="../assembly/target/geronimo-${pom.currentVersion}/bin/deployer.jar"
failonerror="true">
> 
> Modified: geronimo/trunk/modules/tomcat/project.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/project.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/tomcat/project.xml&r1=109825&p2=geronimo/trunk/modules/tomcat/project.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/tomcat/project.xml	(original)
> +++ geronimo/trunk/modules/tomcat/project.xml	Sat Dec  4 13:09:00 2004
> @@ -49,6 +49,16 @@
>      <dependencies>
>          <dependency>
>              <groupId>geronimo</groupId>
> +            <artifactId>geronimo-deployment</artifactId>
> +            <version>${pom.currentVersion}</version>
> +        </dependency>
> +        <dependency>
> +            <groupId>geronimo</groupId>
> +            <artifactId>geronimo-j2ee-builder</artifactId>
> +            <version>${pom.currentVersion}</version>
> +        </dependency>
> +        <dependency>
> +            <groupId>geronimo</groupId>
>              <artifactId>geronimo-kernel</artifactId>
>              <version>${pom.currentVersion}</version>
>          </dependency>
> @@ -65,6 +75,19 @@
>                  <repository>true</repository>
>              </properties>
>          </dependency>
> +       <dependency>
> +            <groupId>geronimo</groupId>
> +            <artifactId>geronimo-j2ee</artifactId>
> +            <version>${pom.currentVersion}</version>           
> +        </dependency>
> +        <dependency>
> +            <groupId>geronimo</groupId>
> +            <artifactId>geronimo-j2ee-schema</artifactId>
> +            <version>${pom.currentVersion}</version>
> +            <properties>
> +                <xmlbeans>true</xmlbeans>
> +            </properties>
> +        </dependency>
>          <dependency>
>              <groupId>tomcat</groupId>
>              <artifactId>catalina</artifactId>
> @@ -168,6 +191,16 @@
>              <groupId>xerces</groupId>
>              <artifactId>xercesImpl</artifactId>
>              <version>&xerces-version;</version>
> +        </dependency>
> +        <dependency>
> +            <groupId>xerces</groupId>
> +            <artifactId>xmlParserAPIs</artifactId>
> +            <version>&xml-parser-apis-version;</version>
> +        </dependency>
> +        <dependency>
> +            <groupId>xmlbeans</groupId>
> +            <artifactId>xbean-apache</artifactId>
> +            <version>&xmlbeans-version;</version>
>          </dependency>
>          <dependency>
>              <groupId>commons-beanutils</groupId>
> 
> Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java?view=diff&rev=109826&p1=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java&r1=109825&p2=geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
(original)
> +++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
Sat Dec  4 13:09:00 2004
> @@ -16,13 +16,17 @@
>   */
>  package org.apache.geronimo.tomcat;
>  
> -import org.apache.catalina.startup.Catalina;
> +import org.apache.catalina.Context;
> +import org.apache.catalina.Engine;
> +import org.apache.catalina.Host;
> +import org.apache.catalina.connector.Connector;
> +import org.apache.catalina.core.StandardHost;
> +import org.apache.catalina.startup.Embedded;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>  import org.apache.geronimo.gbean.GBeanInfo;
>  import org.apache.geronimo.gbean.GBeanInfoBuilder;
>  import org.apache.geronimo.gbean.GBeanLifecycle;
> -import org.apache.geronimo.system.serverinfo.ServerInfo;
>  
>  /**
>   * Apache Tomcat GBean
> @@ -37,37 +41,39 @@
>      private static final Log log = LogFactory.getLog(TomcatContainer.class);
>  
>      /**
> -     * Reference to the org.apache.catalina.startup.Bootstrap shell. Right now
> -     * we're just wrapping up the shell, but we'll be replacing it with our own
> -     * GBean shell for ease of management.
> +     * Reference to the org.apache.catalina.Embedded shell.
>       */
> -    private Catalina shell;
> +    private Embedded shell;
>  
>      /**
> -     * Used to resolve the location of the configuration file.
> +     * Tomcat Host that will contain deployed contexts (webapps)
>       */
> -    private final ServerInfo serverInfo;
> +    private Host host;
>  
> -    private String catalinaHome;
> -
> -    private String catalinaBase;
> +    /**
> +     * Tomcat Engine that will contain the host
> +     */
> +    private Engine engine;
>  
> -    private String catalinaConfig = "var/catalina/server.xml";
> +    /**
> +     * Tomcat Connector that will process requests
> +     * 
> +     * TODO: Make it a GBean
> +     */
> +    private Connector connector;
>  
>      /**
> -     * Reference to the Catalina shell, to which calls are delegated.
> +     * Tomcat default Context
>       * 
> -     * The catalina shell relies on the "catalina.home" and "catalina.base"
> -     * System properties. Presumably, these could be added in a simple
> -     * properties file, but I'm going to work under the assumption that we'll
> -     * want them as persistent attributes in a server configuration. This will
> -     * make them more easily manageable (in theory--we'll see)
> +     * TODO: Make it a gbean
>       */
> -    public TomcatContainer(ServerInfo serverInfo, String catalinaHome, String catalinaBase,
String catalinaConfig) {
> -        this.serverInfo = serverInfo;
> -        this.catalinaHome = catalinaHome;
> -        this.catalinaBase = catalinaBase;
> -        this.catalinaConfig = catalinaConfig;
> +    private Context defaultContext;
> +
> +    /**
> +     * GBean constructor (invoked dynamically when the gbean is declared in a
> +     * plan)
> +     */
> +    public TomcatContainer() {
>      }
>  
>      public void doFail() {
> @@ -77,27 +83,74 @@
>          }
>      }
>  
> +    /**
> +     * Instantiate and start up Tomcat's Embedded class
> +     * 
> +     * See org.apache.catalina.startup.Embedded for details (TODO: provide the
> +     * link to the javadoc)
> +     */
>      public void doStart() throws Exception {
> -        log.debug("catalinaHome: " + catalinaHome + ", catalinaBase: " + catalinaBase
+ ", catalinaConfig: "
> -                + catalinaConfig);
> +        log.debug("doStart()");
> +
> +        // The comments are from the javadoc of the Embedded class
> +
> +        // 1. Instantiate a new instance of this class.
>          if (shell == null) {
> -            shell = new Catalina();
> -        }
> -        if (catalinaHome != null && catalinaHome.length() > 0) {
> -            catalinaHome = serverInfo.resolve(catalinaHome).getPath();
> -            log.debug("catalinaHome ServerInfo.resolve'd: " + catalinaHome);
> -            shell.setCatalinaHome(catalinaHome);
> +            shell = new Embedded();
>          }
> -        if (catalinaBase != null && catalinaBase.length() > 0) {
> -            catalinaBase = serverInfo.resolve(catalinaBase).getPath();
> -            log.debug("catalinaBase ServerInfo.resolve'd: " + catalinaBase);
> -            shell.setCatalinaBase(catalinaBase);
> -        }
> -        if (catalinaConfig != null && catalinaConfig.length() > 0) {
> -            shell.setConfig(catalinaConfig);
> -        }
> -        shell.setParentClassLoader(this.getClass().getClassLoader());
> +
> +        // 2. Set the relevant properties of this object itself. In particular,
> +        // you will want to establish the default Logger to be used, as well as
> +        // the default Realm if you are using container-managed security.
>          shell.setUseNaming(false);
> +
> +        // 3. Call createEngine() to create an Engine object, and then call its
> +        // property setters as desired.
> +        engine = shell.createEngine();
> +        engine.setName("Geronimo");
> +
> +        // 4. Call createHost() to create at least one virtual Host associated
> +        // with the newly created Engine, and then call its property setters as
> +        // desired. After you customize this Host, add it to the corresponding
> +        // Engine with engine.addChild(host).
> +        host = shell.createHost("localhost", "");
> +        // TODO: Make it that gbean's attribute or tomcatwebappcontext's one
> +        ((StandardHost) host).setWorkDir("var/catalina");
> +        
> +        engine.setDefaultHost(host.getName());
> +        host.setParent(engine);
> +        engine.addChild(host);
> +
> +        // 5. Call createContext() to create at least one Context associated
> +        // with each newly created Host, and then call its property setters as
> +        // desired. You SHOULD create a Context with a pathname equal to a
> +        // zero-length string, which will be used to process all requests not
> +        // mapped to some other Context. After you customize this Context, add
> +        // it to the corresponding Host with host.addChild(context).
> +        defaultContext = shell.createContext("", "");
> +        host.addChild(defaultContext);
> +
> +        // 6. Call addEngine() to attach this Engine to the set of defined
> +        // Engines for this object.
> +        shell.addEngine(engine);
> +
> +        // 7. Call createConnector() to create at least one TCP/IP connector,
> +        // and then call its property setters as desired.
> +
> +        // It doesn't work - there's no HTTP connector created
> +        // connector = shell.createConnector((String) null, 8080, "http");
> +
> +        // Create an HTTP/1.1 connector manually
> +        connector = new Connector("HTTP/1.1");
> +        connector.setPort(8080);
> +
> +        // 8. Call addConnector() to attach this Connector to the set of defined
> +        // Connectors for this object. The added Connector will use the most
> +        // recently added Engine to process its received requests.
> +        shell.addConnector(connector);
> +
> +        // 9. Call start() to initiate normal operations of all the attached
> +        // components.
>          shell.start();
>      }
>  
> @@ -108,17 +161,34 @@
>          }
>      }
>  
> +    /**
> +     * Creates and adds the context to the running host
> +     * 
> +     * It simply delegates the call to Tomcat's Embedded and Host classes
> +     * 
> +     * @param ctx
> +     *            the context to be added
> +     * 
> +     * @see org.apache.catalina.startup.Embedded
> +     * @see org.apache.catalina.Host
> +     */
> +    public void addContext(Context ctx) {
> +        ctx.setParent(host);
> +        host.addChild(ctx);
> +    }
> +
> +    public void removeContext(Context ctx) {
> +        shell.removeContext(ctx);
> +    }
> +
>      public static final GBeanInfo GBEAN_INFO;
>  
>      static {
>          GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Tomcat Web Container",
TomcatContainer.class);
>  
> -        infoFactory.setConstructor(new String[] { "ServerInfo", "CatalinaHome", "CatalinaBase",
"CatalinaConfig" });
> +        infoFactory.addOperation("addContext", new Class[] { Context.class });
> +        infoFactory.addOperation("removeContext", new Class[] { Context.class });
>  
> -        infoFactory.addReference("ServerInfo", ServerInfo.class);
> -        infoFactory.addAttribute("CatalinaHome", String.class, true);
> -        infoFactory.addAttribute("CatalinaBase", String.class, true);
> -        infoFactory.addAttribute("CatalinaConfig", String.class, true);
>          GBEAN_INFO = infoFactory.getBeanInfo();
>      }
>  
> 
> Added: 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=auto&rev=109826
> ==============================================================================
> --- (empty file)
> +++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
Sat Dec  4 13:09:00 2004
> @@ -0,0 +1,107 @@
> +/**
> + *
> + * 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;
> +
> +import java.net.MalformedURLException;
> +import java.net.URI;
> +import java.net.URL;
> +
> +import org.apache.catalina.LifecycleException;
> +import org.apache.catalina.core.StandardContext;
> +import org.apache.catalina.loader.WebappClassLoader;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.apache.geronimo.gbean.GBeanInfo;
> +import org.apache.geronimo.gbean.GBeanInfoBuilder;
> +import org.apache.geronimo.gbean.GBeanLifecycle;
> +import org.apache.geronimo.gbean.WaitingException;
> +
> +/**
> + * Wrapper for a WebApplicationContext that sets up its J2EE environment.
> + * 
> + * @version $Rev: 56022 $ $Date: 2004-10-30 07:16:18 +0200 (Sat, 30 Oct 2004) $
> + */
> +public class TomcatWebAppContext extends StandardContext implements GBeanLifecycle {
> +
> +    private static Log log = LogFactory.getLog(TomcatWebAppContext.class);
> +
> +    private final TomcatContainer container;
> +
> +    private final URI webAppRoot;
> +
> +    public TomcatWebAppContext(URI webAppRoot, URI[] webClassPath, URL configurationBaseUrl,
TomcatContainer container)
> +            throws MalformedURLException {
> +
> +        assert webAppRoot != null;
> +        assert webClassPath != null;
> +        assert configurationBaseUrl != null;
> +        assert container != null;
> +
> +        this.webAppRoot = webAppRoot;
> +        this.container = container;
> +
> +        this.setDocBase(this.webAppRoot.getPath());
> +    }
> +
> +    public void doStart() throws WaitingException, Exception {
> +
> +        container.addContext(this);
> +        super.start();
> +
> +        log.info("TomcatWebAppContext started");
> +    }
> +
> +    public void doStop() throws Exception {
> +        super.stop();
> +        container.removeContext(this);
> +
> +        log.info("TomcatWebAppContext stopped");
> +    }
> +
> +    public void doFail() {
> +        try {
> +            super.stop();
> +        } catch (LifecycleException e) {
> +        }
> +
> +        container.removeContext(this);
> +        log.info("TomcatWebAppContext failed");
> +    }
> +
> +    public static final GBeanInfo GBEAN_INFO;
> +
> +    static {
> +        GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Tomcat WebApplication Context",
TomcatWebAppContext.class);
> +
> +        infoFactory.addAttribute("webAppRoot", URI.class, true);
> +        infoFactory.addAttribute("webClassPath", URI[].class, true);
> +        infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
> +
> +        infoFactory.addAttribute("path", String.class, true);
> +
> +        infoFactory.addReference("Container", TomcatContainer.class);
> +
> +        infoFactory.setConstructor(new String[] { "webAppRoot", "webClassPath", "configurationBaseUrl",
"Container", });
> +
> +        GBEAN_INFO = infoFactory.getBeanInfo();
> +    }
> +
> +    public static GBeanInfo getGBeanInfo() {
> +        return GBEAN_INFO;
> +    }
> +}
> 
> Added: 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=auto&rev=109826
> ==============================================================================
> --- (empty file)
> +++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Sat Dec  4 13:09:00 2004
> @@ -0,0 +1,235 @@
> +/**
> + *
> + * 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.deployment.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.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 static final Log log = LogFactory.getLog(TomcatModuleBuilder.class);
> +
> +    public TomcatModuleBuilder() {
> +        log.debug("TomcatModuleBuilder()");
> +    }
> +
> +    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;
> +
> +        WebAppType webApp = (WebAppType) webModule.getSpecDD();
> +        // JettyWebAppType jettyWebApp = (JettyWebAppType)
> +        // webModule.getVendorDD();
> +
> +        // 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;
> +        }
> +
> +        WebModule module = null;
> +        try {
> +            long randomName = System.currentTimeMillis();
> +            module = new WebModule(false, new URI("org/apache/geronimo/" + randomName),
new URI(
> +                    "org/apache/geronimo/Server"), moduleFile, "war", null, null, null);
> +            module.setContextRoot("/" + randomName);
> +        } catch (URISyntaxException e) {
> +            throw new DeploymentException(e);
> +        }
> +        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);
> +        }
> +    }
> +
> +    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.addInterface(ModuleBuilder.class);
> +
> +        GBEAN_INFO = infoBuilder.getBeanInfo();
> +    }
> +
> +    public static GBeanInfo getGBeanInfo() {
> +        return GBEAN_INFO;
> +    }
> +}
> 
> Modified: geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml
> Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml?view=diff&rev=109826&p1=geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml&r1=109825&p2=geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml&r2=109826
> ==============================================================================
> --- geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml	(original)
> +++ geronimo/trunk/modules/tomcat/src/plan/tomcat-plan.xml	Sat Dec  4 13:09:00 2004
> @@ -68,11 +68,6 @@
>          <uri>xerces/jars/xercesImpl-2.6.0.jar</uri>
>      </dependency>
>  
> -    <gbean name="geronimo.server:type=WebContainer,container=Apache Tomcat" class="org.apache.geronimo.tomcat.TomcatContainer">
> -        <reference name="ServerInfo">geronimo.system:role=ServerInfo</reference>
> -    	<attribute name="CatalinaHome" type="java.lang.String">var/catalina</attribute>
> -    	<attribute name="CatalinaBase" type="java.lang.String">var/catalina</attribute>
> -    	<attribute name="CatalinaConfig" type="java.lang.String">conf/server.xml</attribute>
> -    </gbean>
> +    <gbean name="geronimo.server:type=WebContainer,container=Tomcat" class="org.apache.geronimo.tomcat.TomcatContainer"/>
>  
>  </configuration>



Mime
View raw message