You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ja...@apache.org on 2003/11/20 10:10:18 UTC

cvs commit: incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty JettyWebAccessLog.java JettyWebApplication.java JettyWebApplicationContext.java

janb        2003/11/20 01:10:18

  Modified:    modules/web/src/java/org/apache/geronimo/web
                        AbstractWebApplication.java
                        AbstractWebContainer.java WebAccessLog.java
                        WebApplication.java
               modules/web/src/java/org/apache/geronimo/web/jetty
                        JettyWebApplication.java
                        JettyWebApplicationContext.java
  Added:       modules/web/src/java/org/apache/geronimo/web
                        AbstractWebAccessLog.java
               modules/web/src/java/org/apache/geronimo/web/jetty
                        JettyWebAccessLog.java
  Log:
  1. changed ReadOnlyContext to javax.naming.Context in interface method signatures to improve pluggability
  2. webapp deploy goal was removed twice from list of goals
  3. fixed up formatting of several classes and added some comments
  4. add new web access log functionality - just waiting for new Jetty snapshot jar to enable it
  5. implemented JSR77 method getDeploymentDescriptor for web applications. Temporary solution only.
  
  Revision  Changes    Path
  1.10      +162 -36   incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java
  
  Index: AbstractWebApplication.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractWebApplication.java	30 Oct 2003 07:47:04 -0000	1.9
  +++ AbstractWebApplication.java	20 Nov 2003 09:10:17 -0000	1.10
  @@ -57,12 +57,21 @@
   package org.apache.geronimo.web;
   
   
  +import java.io.StringWriter;
   import java.net.URI;
  +
  +import javax.naming.Context;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.core.service.AbstractManagedComponent;
   import org.apache.geronimo.core.service.Container;
  -
  +import org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
  +import org.apache.geronimo.deployment.model.web.Servlet;
  +import org.apache.geronimo.deployment.model.web.WebApp;
  +import org.apache.geronimo.xml.deployment.WebAppLoader;
  +import org.apache.geronimo.xml.deployment.StorerUtil;
  +import org.w3c.dom.Document;
   
   
   /**
  @@ -76,18 +85,37 @@
    */
   public abstract class AbstractWebApplication extends AbstractManagedComponent implements WebApplication {
   
  -     private final static Log log = LogFactory.getLog(AbstractWebApplication.class);
  +    private final static Log log = LogFactory.getLog(AbstractWebApplication.class);
   
  +    //uri of the webapp
       protected URI uri; 
  -
       
  -   /**
  -     * Class loading delegation model
  -     */
  +    // pojo for web.xml
  +    protected WebApp webDDObj;
  +    
  +    // pojo for geronimo-web.xml
  +    protected GeronimoWebAppDocument geronimoDDObj;
  +    
  +    // parsed web.xml
  +    protected Document deploymentDescriptorDoc;
  +    
  +    // deployment descriptor as a string
  +    protected String deploymentDescriptorStr;
  +    
  +    //jndi context for webapp
  +    protected Context context;
  +    
  +    //servlet definitions
  +    protected String[] servlets;
  +    
  +    // context path of webapp
  +    protected String contextPath;
  +    
  +    //class loading delegation model. Default to web-app scope
       private boolean java2ClassloadingCompliance = false;
   
   
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Creates a new <code>AbstractWebApplication</code> instance.
        *
  @@ -96,7 +124,7 @@
       
       }
       
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Creates a new <code>AbstractWebApplication</code> instance.
        *
  @@ -109,17 +137,17 @@
   
       
     
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Start the webapp. Called by the container or management interface
        * @throws Exception
        * @throws IllegalStateException
        */
       public void doStart() throws Exception {
  -       
  +           
       }
   
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Stop the webapp. Called by the container, or by mangement
        * interface
  @@ -131,19 +159,18 @@
     
   
       
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /** Get the URI of this webapp
        * @return the URI of the webapp
        * @see org.apache.geronimo.web.WebApplication#getURI()
        */
  -    public URI getURI ()
  -    {
  +    public URI getURI (){
           return uri;
       }
   
    
   
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Setter for classloading compliance. If true, then classloading will
        * delegate first to parent classloader a la Java2 spec. If false, then
  @@ -154,7 +181,7 @@
           java2ClassloadingCompliance = state;
       }
   
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /**
        * Getter for classloading compliance.
        * @return truen if application is using Java 2 compliant class loading
  @@ -164,61 +191,160 @@
       }
   
   
  -    /* -------------------------------------------------------------------------------------- */
  +    
       /** Set the container to which this webapp belongs.
        * In turn, we add ourselves as a component to that container.
        * @param container
        * @see org.apache.geronimo.core.service.Component#setContainer(org.apache.geronimo.core.service.Container)
        */
  -    public void setContainer (Container container)
  -    {
  +    public void setContainer (Container container) {
           super.setContainer(container);
  -        
           container.addComponent (this);
       }
     
  -    /* -------------------------------------------------------------------------------------- */
  +   
        /** JSR077
         * Return the list of Servlets of this webapp
         * @return
         * @see org.apache.geronimo.web.WebApplication#getServlets()
         */
        public String[] getServlets() {
  -         //TODO
  -         return null;
  +        if (servlets == null) {
  +            if (webDDObj == null) 
  +                return null;
  +           
  +           Servlet[] servletObjs = webDDObj.getServlet();
  +           servlets = new String[servletObjs.length];
  +           for (int i=0; i<servletObjs.length; i++) {
  +               servlets[i] = servletObjs[i].getServletName();             
  +           }
  +        }
  +        
  +        return servlets;
        }
   
  -     /* -------------------------------------------------------------------------------------- */
  +   
        /** JSR077
  +      * TODO: This method should be able to be implemented based on the pojos. 
  +      *  Need a method to get from pojo->xml->string
         * @return web.xml as a string
         * @see org.apache.geronimo.web.WebApplication#getDeploymentDescriptor()
         */
  -     public String getDeploymentDescriptor() {
  -         //TODO
  -         return null;
  -     }
  +     public abstract String getDeploymentDescriptor();
  +    
   
  -  
  -    /* -------------------------------------------------------------------------------------- */
  +
  +    
       /**JSR077
        * @return ObjectName(s) as string of JVM(s) on which this webapp is deployed
        * @see org.apache.geronimo.kernel.management.J2EEModule#getJavaVMs()
        */
  -    public String[] getJavaVMs()
  -    {
  +    public String[] getJavaVMs() {
           // TODO
           return null;
       }
   
  -    /* -------------------------------------------------------------------------------------- */
  +
       /** JSR077 
        * @return ObjectName as string of Geronimo server  on which this webapp is deployed
        * @see org.apache.geronimo.kernel.management.J2EEDeployedObject#getServer()
        */
  -    public String getServer()
  -    {
  +    public String getServer() {
  +        // TODO
  +        return null;
  +    }
  +
  +
  +    
  +    /* 
  +     * @return
  +     * @see org.apache.geronimo.web.WebApplication#getComponentContext()
  +     */
  +    public Context getComponentContext() {
  +        return context;
  +    }
  +
  +
  +    /* 
  +     * @param context
  +     * @see org.apache.geronimo.web.WebApplication#setComponentContext(javax.naming.Context)
  +     */
  +    public void setComponentContext(Context context) {
  +        this.context = context;
  +    }
  +    
  +    /* 
  +     * @return
  +     * @see org.apache.geronimo.web.WebApplication#getContextPath()
  +     */
  +    public String getContextPath() {
  +        return contextPath;
  +    }
  +
  + 
  +    /* 
  +     * @param path
  +     * @see org.apache.geronimo.web.WebApplication#setContextPath(java.lang.String)
  +     */
  +    public void setContextPath(String path) {
  +        contextPath = path;
  +    }
  +    
  +    
  +    /* 
  +     * @return
  +     * @see org.apache.geronimo.web.WebApplication#getParentClassLoader()
  +     */
  +    public ClassLoader getParentClassLoader() {
           // TODO
           return null;
       }
  +
  +    
  +
  +   
  +
  +   
  +    /* 
  +     * @param loader
  +     * @see org.apache.geronimo.web.WebApplication#setParentClassLoader(java.lang.ClassLoader)
  +     */
  +    public void setParentClassLoader(ClassLoader loader) {
  +
  +    }
  +
  +
  + 
  +    
  +    /* 
  +     * 
  +     * @see org.apache.geronimo.web.WebApplication#setGeronimoDDObj()
  +     */
  +    public void setGeronimoDDObj(GeronimoWebAppDocument geronimoDDObj) {
  +        this.geronimoDDObj = geronimoDDObj;
  +    }
  + 
  + 
  +    /* 
  +     * @return
  +     * @see org.apache.geronimo.web.WebApplication#getGeronimoDDObj()
  +     */
  +    public GeronimoWebAppDocument getGeronimoDDObj() {
  +        return geronimoDDObj;
  +    }
  +
  +    /* 
  +     * @param webDDObj
  +     * @see org.apache.geronimo.web.WebApplication#setWebDDObj(org.apache.geronimo.deployment.model.web.WebApp)
  +     */
  +    public void setWebDDObj(WebApp webDDObj) {
  +        this.webDDObj = webDDObj;
  +    }
  +    
  +    public WebApp getWebDDObj () {
  +        return webDDObj;
  +    }
  +
  + 
   
   }
  
  
  
  1.20      +30 -10    incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebContainer.java
  
  Index: AbstractWebContainer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebContainer.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- AbstractWebContainer.java	17 Nov 2003 07:33:51 -0000	1.19
  +++ AbstractWebContainer.java	20 Nov 2003 09:10:17 -0000	1.20
  @@ -84,6 +84,7 @@
   import org.apache.geronimo.core.service.AbstractManagedContainer;
   import org.apache.geronimo.core.service.Component;
   import org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
  +import org.apache.geronimo.deployment.model.web.WebApp;
   import org.apache.geronimo.kernel.deployment.DeploymentException;
   import org.apache.geronimo.kernel.deployment.DeploymentHelper;
   import org.apache.geronimo.kernel.deployment.DeploymentInfo;
  @@ -108,6 +109,7 @@
   import org.apache.geronimo.web.deploy.RemoveWebApplication;
   import org.apache.geronimo.xml.deployment.GeronimoWebAppLoader;
   import org.apache.geronimo.xml.deployment.LoaderUtil;
  +import org.apache.geronimo.xml.deployment.WebAppLoader;
   
   import org.w3c.dom.Document;
   import org.xml.sax.SAXException;
  @@ -212,10 +214,11 @@
   
           URL url = goal.getUrl();
           DeploymentHelper deploymentHelper = new DeploymentHelper(url, goal.getType(), "WebApplication", "web.xml", "geronimo-web.xml", "WEB-INF");
  -        URL geronimoURL = deploymentHelper.locateGeronimoDD();
  -
  +        URL geronimoDDURL = deploymentHelper.locateGeronimoDD();
  +        URL webDDURL = deploymentHelper.locateJ2eeDD();
  +        
           // Is the specific URL deployable?
  -        if (null == geronimoURL) {
  +        if (null == geronimoDDURL) {
   //            log.info("Looking at and rejecting url " + url);
               return false;
           }
  @@ -224,7 +227,7 @@
           log.trace("Planning the ejb module deployment " + url);
   
           // One can deploy the specified URL. One removes it from the current goal set.
  -        goals.remove(goal);
  +        //goals.remove(goal);
   
           ObjectName deploymentUnitName = deploymentHelper.buildDeploymentName();
   
  @@ -241,22 +244,33 @@
           deploymentInfoPlan.addTask(new CreateClassSpace(server, classSpaceMetaData));
           plans.add(deploymentInfoPlan);
   
  -        // Load the deployment descriptor into our POJO
  -        URI geronimoWebURI = URI.create(geronimoURL.toString()).normalize();
  -        log.trace("Loading deployment descriptor " + geronimoWebURI);
  +        // Load the geronimo-web.xml descriptor into our POJO
  +        log.trace("Loading deployment descriptor " + geronimoDDURL.toString());
   
           GeronimoWebAppDocument geronimoWebAppDoc = null;
           try {
  -            Document document = LoaderUtil.parseXML(new InputStreamReader(geronimoURL.openStream()));
  +            Document document = LoaderUtil.parseXML(new InputStreamReader(geronimoDDURL.openStream()));
               geronimoWebAppDoc = GeronimoWebAppLoader.load(document);
           } catch (FileNotFoundException e) {
  -//            throw new DeploymentException("Deployment descriptor not found", e);
  +//            throw new DeploymentException("geronimo-web.xml not found", e);
           } catch (SAXException e) {
               throw new DeploymentException("geronimo-web.xml malformed", e);
           } catch (IOException e) {
               throw new DeploymentException("Deployment descriptor not readable", e);
           }
   
  +        //load the web.xml descriptor into a POJO
  +        WebApp webAppDoc = null;
  +        try {
  +            Document doc = LoaderUtil.parseXML (new InputStreamReader (webDDURL.openStream()));
  +            webAppDoc = WebAppLoader.load(doc);
  +        } catch (FileNotFoundException e) {
  +            throw new DeploymentException ("web.xml file not found", e);
  +        }catch (SAXException e) {
  +            throw new DeploymentException ("web.xml malformed", e);
  +        } catch (IOException e) {
  +            throw new DeploymentException ("web.xml not readable", e);
  +        }
           // Create a webapp typed to the concrete type of the web container
           WebApplication webapp = createWebApplication(baseURI);
           ObjectName webappName;
  @@ -266,6 +280,7 @@
               throw new DeploymentException(e);
           }
   
  +       
           // Create a deployment plan for the webapp
           DeploymentPlan webappPlan = new DeploymentPlan();
           webappPlan.addTask(new RegisterMBeanInstance(server, webappName, webapp));
  @@ -280,6 +295,11 @@
           webappMetadata.setLoaderName(classSpaceMetaData.getName());
           dependencyService.addStartDependency(webappName, deploymentUnitName);
   
  +        // Set up the web.xml POJO
  +        webapp.setWebDDObj (webAppDoc);
  +        // Set up the geronimo-web.xml POJO
  +        webapp.setGeronimoDDObj (geronimoWebAppDoc);
  +        
           // Set up the ContextPath, which can come from:
           //  application.xml
           //  geronimo-web.xml
  
  
  
  1.6       +134 -10   incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebAccessLog.java
  
  Index: WebAccessLog.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebAccessLog.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WebAccessLog.java	30 Oct 2003 07:47:05 -0000	1.5
  +++ WebAccessLog.java	20 Nov 2003 09:10:17 -0000	1.6
  @@ -59,6 +59,13 @@
   import java.net.URI;
   import org.apache.geronimo.core.service.ManagedComponent;
   
  +/* -------------------------------------------------------------------------------------- */
  +/**
  + * WebAccessLog
  + * 
  + * 
  + * @version $Revision$ $Date$
  + */
   /**
    * WebAccessLog
    *
  @@ -67,19 +74,136 @@
    * @version $Revision$ $Date$
    */
   public interface WebAccessLog extends ManagedComponent {
  +    public static final String NCSA_COMMON_PATTERN = "%h %l %u %t \"%r\" %>s %b";
  +    public static final String NCSA_EXTENDED_PATTERN = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"";
  +    
  +    public static final String NCSA_COMMON_NAME = "common";
  +    public static final String NCSA_EXTENDED_NAME = "extended";
       
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Set the name of a log implementation class.
  +     * This is useful for containers that have a number of different
  +     * log implementations that may be plugged in.
  +     * @param classname fully qualified classname
  +     */
  +    public void setLogImpl (String classname);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the name of the log implementation class.
  +     * @return
  +     */
  +    public String getLogImpl ();
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /**Set directory where access log logs will be written
  +     * @param uri
  +     */
       public void setLogLocation(URI uri);
   
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get location as uri of access log directory
  +     * @return
  +     */
       public URI getLogLocation();
   
  -    // extendedNCSAFormat
  -
  -    // rollover retention days
  -
  -    // date format
  -
  -    // append
  -
  -    // buffering
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Set the log format in accordance with NCSA spec
  +     * @param pattern
  +     */
  +    public void setLogPattern (String pattern);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the NCSA style log format pattern
  +     * @return
  +     */
  +    public String getLogPattern ();
  +   
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Configure the number of days before old logs are deleted.
  +     * @param days
  +     */
  +    public void setLogRetentionDays (int days);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the number of days before old logs are deleted
  +     * @return
  +     */
  +    public int getLogRetentionDays ();
  +
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Number of hrs between log rotations
  +     *  eg 1 = 1hr, 24=1day, 168=1week
  +     * @param 0 is no rotation, otherwise it is hrs between rotations
  +     */
  +    public void setLogRolloverIntervalHrs (int hrs);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Number of hrs between log rotations
  +     * @return
  +     */
  +    public int getLogRolloverIntervalHrs ();
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Prefix to prepend to all access log filenames
  +     * @param prefix
  +     */
  +    public void setLogPrefix (String prefix);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the log filename prefix
  +     * @return the prefix, or null if not set
  +     */
  +    public String getLogPrefix ();
  +    
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Suffix to append to all access log filenames
  +     * @param suffix
  +     */
  +    public void setLogSuffix (String suffix);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the log filename suffix
  +     * @return the suffix, or null if not set
  +     */
  +    public String getLogSuffix ();
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Set the format for the date in the log
  +     * @param dateFormat 
  +     * @see java.util.DateFormat
  +     */
  +    public void setLogDateFormat (String dateFormat);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get the date format string
  +     * @return 
  +     */
  +    public String getLogDateFormat ();
  +  
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Configure DNS resolution of host addresses in the log
  +     * @param state
  +     */
  +    public void setResolveHostNames (boolean state);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get state of DNS hostname resolution for the log
  +     * @return true if DNS resolution is enabled, false otherwise
  +     */
  +    public boolean getResolveHostNames ();
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Configure if logs will be appended or created afresh
  +     * @param state true if appending is enabled, false otherwise
  +     */
  +    public void setAppend (boolean state);
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +    /** Get whether logs will be appended
  +     * @return true if appending is enabled, false otherwise
  +     */
  +    public boolean getAppend ();
   
   }
  
  
  
  1.13      +24 -5     incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebApplication.java
  
  Index: WebApplication.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebApplication.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- WebApplication.java	16 Nov 2003 22:36:31 -0000	1.12
  +++ WebApplication.java	20 Nov 2003 09:10:17 -0000	1.13
  @@ -58,9 +58,11 @@
   import java.net.URI;
   
   import org.apache.geronimo.core.service.Component;
  +import org.apache.geronimo.deployment.model.web.WebApp;
  +import org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
   import org.apache.geronimo.kernel.management.WebModule;
  -import org.apache.geronimo.naming.java.ReadOnlyContext;
  -
  +import javax.naming.Context;
  +import org.w3c.dom.Document;
   
   /**
    * The WebApplication interface represents a web application deployable within a WebContainer.
  @@ -106,6 +108,23 @@
        * @return the contents of the web.xml as a string
        */
       public String getDeploymentDescriptor();
  +    
  +    
  +    /** Configure the pojo for the web.xml
  +     * @param webDDObj
  +     */
  +    public void setWebDDObj (WebApp webDDObj);
  +    
  +    //public WebApp getWebDDObj ();
  +    
  +
  +    /** Configure the pojo for the geronimo-web.xml
  +     * @param geronimoDDObj
  +     */
  +    public void setGeronimoDDObj (GeronimoWebAppDocument geronimoDDObj);
  +    
  +    public GeronimoWebAppDocument getGeronimoDDObj();
  +    
   
       /**
        * Getter for the class loader delegation model for this webapp
  @@ -123,11 +142,11 @@
        * Gets the JNDI context for the web application.
        * @return the jndi context
        */
  -    public ReadOnlyContext getComponentContext();
  +    public Context getComponentContext();
   
       /**
        * Sets the JNDI context for the web application.
        * @param context the jndi context
        */
  -    public void setComponentContext(ReadOnlyContext context);
  +    public void setComponentContext(Context context);
   }
  
  
  
  1.1                  incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebAccessLog.java
  
  Index: AbstractWebAccessLog.java
  ===================================================================
  /* ====================================================================
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" and
  *    "Apache Geronimo" must not be used to endorse or promote products
  *    derived from this software without prior written permission. For
  *    written permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache",
  *    "Apache Geronimo", nor may "Apache" appear in their name, without
  *    prior written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  *
  * ====================================================================
  */
  
  
  package org.apache.geronimo.web;
  
  import org.apache.geronimo.core.service.AbstractManagedComponent;
  import org.apache.geronimo.core.service.Container;
  
  import java.net.URI;
  
  
  
  /* -------------------------------------------------------------------------------------- */
  /**
   * AbstractWebAccessLog
   * 
   * * @jmx:mbean extends="org.apache.geronimo.web.WebAccessLog, org.apache.geronimo.kernel.management.StateManageable"
   * @version $Revision: 1.1 $ $Date: 2003/11/20 09:10:17 $
   */
  public abstract class AbstractWebAccessLog extends AbstractManagedComponent implements WebAccessLog, AbstractWebAccessLogMBean
  {
      protected String logImpl;
      protected URI logLocation;
      protected String logPattern;
      protected String logSuffix;
      protected String logPrefix;
      protected String logDateFormat;
      protected int rolloverHrs =0;
      protected boolean resolutionEnabled = false;
      protected boolean appendEnabled = true;
      protected int logRetentionDays;
      
      
      
      
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param uri
       * @see org.apache.geronimo.web.WebAccessLog#setLogLocation(java.net.URI)
       */
      public void setLogLocation(URI uri)
      {
           logLocation = uri;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogLocation()
       */
      public URI getLogLocation()
      {
          return logLocation;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param pattern
       * @see org.apache.geronimo.web.WebAccessLog#setLogPattern(java.lang.String)
       */
      public void setLogPattern(String pattern)
      {
          if (pattern.equalsIgnoreCase (NCSA_COMMON_NAME))
              logPattern = NCSA_COMMON_PATTERN;
           else if (pattern.equalsIgnoreCase (NCSA_EXTENDED_NAME))
               logPattern = NCSA_EXTENDED_PATTERN;
           else    
               logPattern = pattern;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogPattern()
       */
      public String getLogPattern()
      {
           return logPattern;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param days
       * @see org.apache.geronimo.web.WebAccessLog#setLogRetentionDays(int)
       */
      public void setLogRetentionDays(int days)
      {
           logRetentionDays = days;        
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogRetentionDays()
       */
      public int getLogRetentionDays()
      {
           return logRetentionDays;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param state
       * @see org.apache.geronimo.web.WebAccessLog#setLogRollover(boolean)
       */
      public void setLogRolloverIntervalHrs(int hrs)
      {
         rolloverHrs = hrs;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogRollover()
       */
      public int getLogRolloverIntervalHrs()
      {
          return rolloverHrs;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param prefix
       * @see org.apache.geronimo.web.WebAccessLog#setLogPrefix(java.lang.String)
       */
      public void setLogPrefix(String prefix)
      {
          logPrefix = prefix;  
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogPrefix()
       */
      public String getLogPrefix()
      {
          return logPrefix;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param suffix
       * @see org.apache.geronimo.web.WebAccessLog#setLogSuffix(java.lang.String)
       */
      public void setLogSuffix(String suffix)
      {
          logSuffix = suffix;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogSuffix()
       */
      public String getLogSuffix()
      {
          return logSuffix;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param dateFormat
       * @see org.apache.geronimo.web.WebAccessLog#setLogDateFormat(java.lang.String)
       */
      public void setLogDateFormat(String dateFormat)
      {
          logDateFormat = dateFormat;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogDateFormat()
       */
      public String getLogDateFormat()
      {
          return logDateFormat;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param state
       * @see org.apache.geronimo.web.WebAccessLog#setResolveHostNames(boolean)
       */
      public void setResolveHostNames(boolean state)
      {
          resolutionEnabled = state;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getResolveHostNames()
       */
      public boolean getResolveHostNames()
      {
          return resolutionEnabled;
      }
  
      public void setContainer (Container container)
      {
          super.setContainer(container);
          
          container.addComponent (this);
      }
    
      protected void doStart() throws Exception
      {
          if (getContainer() == null)
              throw new IllegalStateException ("WebAccessLog has no web container");
  
      }
      
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getAppend()
       */
      public boolean getAppend()
      {
          return appendEnabled;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param state
       * @see org.apache.geronimo.web.WebAccessLog#setAppend(boolean)
       */
      public void setAppend(boolean state)
      {
           appendEnabled = state;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @return
       * @see org.apache.geronimo.web.WebAccessLog#getLogImpl()
       */
      public String getLogImpl()
      {
          return logImpl;
      }
  
      /* -------------------------------------------------------------------------------------- */
      /* 
       * @param classname
       * @see org.apache.geronimo.web.WebAccessLog#setLogImpl(java.lang.String)
       */
      public void setLogImpl(String classname)
      {
          logImpl = classname;
      }
  
  }
  
  
  
  1.6       +49 -7     incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java
  
  Index: JettyWebApplication.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JettyWebApplication.java	16 Nov 2003 22:36:31 -0000	1.5
  +++ JettyWebApplication.java	20 Nov 2003 09:10:17 -0000	1.6
  @@ -1,15 +1,19 @@
   package org.apache.geronimo.web.jetty;
   
  +import java.io.BufferedReader;
  +import java.io.IOException;
  +import java.io.InputStreamReader;
   import java.net.URI;
  +import java.net.URL;
  +
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
  +import javax.naming.Context;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.web.AbstractWebApplication;
   import org.apache.geronimo.web.WebContainer;
  -import org.apache.geronimo.naming.java.ReadOnlyContext;
  -
   import org.mortbay.jetty.servlet.WebApplicationContext;
   
   
  @@ -26,6 +30,7 @@
       private JettyWebApplicationContext jettyContext;
       private final Log log = LogFactory.getLog(getClass());
   
  +    
       public JettyWebApplication() {
           super();
           jettyContext = new JettyWebApplicationContext();
  @@ -68,9 +73,46 @@
           return jettyContext.getContextPath();
       }
   
  +   
  +    /* Hacky implementation of getting the web.xm as a String.
  +     * This should be handled by converting pojo->xml->string
  +     * @return
  +     * @see org.apache.geronimo.kernel.management.J2EEDeployedObject#getDeploymentDescriptor()
  +     */
       public String getDeploymentDescriptor() {
  -        //TODO
  -        return null;
  +        if (deploymentDescriptorStr != null)
  +            return deploymentDescriptorStr;
  +            
  +        BufferedReader reader = null;
  +        try {
  +            URL url = new URL (jettyContext.getDeploymentDescriptor());
  +            StringBuffer strbuff = new StringBuffer();
  +            reader = new BufferedReader(new InputStreamReader (url.openStream()));
  +            boolean more = true;
  +            while (more) {
  +                String line = reader.readLine ();
  +                if (line == null)
  +                    more = false;
  +                else
  +                    strbuff.append (line);
  +            }
  +            
  +            deploymentDescriptorStr = strbuff.toString();
  +
  +            return deploymentDescriptorStr;
  +            
  +        } catch (IOException e) {
  +            log.error (e);
  +            return null;
  +        }
  +        finally {
  +            try {
  +                reader.close();
  +            } catch (IOException e) {
  +                log.warn("Error closing web.xml reader", e);
  +            }
  +            
  +        }    
       }
   
       public boolean getJava2ClassloadingCompliance() {
  @@ -85,11 +127,11 @@
           return jettyContext;
       }
   
  -    public ReadOnlyContext getComponentContext() {
  +    public Context getComponentContext() {
           return jettyContext.getComponentContext();
       }
   
  -    public void setComponentContext(ReadOnlyContext context) {
  +    public void setComponentContext(Context context) {
           jettyContext.setComponentContext(context);
       }
   
  
  
  
  1.2       +6 -5      incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplicationContext.java
  
  Index: JettyWebApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplicationContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JettyWebApplicationContext.java	16 Nov 2003 07:17:29 -0000	1.1
  +++ JettyWebApplicationContext.java	20 Nov 2003 09:10:18 -0000	1.2
  @@ -55,6 +55,7 @@
    */
   package org.apache.geronimo.web.jetty;
   
  +import javax.naming.Context;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.naming.java.ReadOnlyContext;
  @@ -70,7 +71,7 @@
    * @version $Revision$ $Date$
    */
   public class JettyWebApplicationContext extends WebApplicationContext {
  -    private ReadOnlyContext componentContext;
  +    private Context componentContext;
       private Log log = LogFactory.getLog(JettyWebApplicationContext.class);
   
       public JettyWebApplicationContext() {
  @@ -82,7 +83,7 @@
   
       public Object enterContextScope(HttpRequest httpRequest, HttpResponse httpResponse) {
           log.info("Entering context " + httpRequest.getRequestURL());
  -        RootContext.setComponentContext(componentContext);
  +        RootContext.setComponentContext((ReadOnlyContext)componentContext);
           return super.enterContextScope(httpRequest, httpResponse);
       }
   
  @@ -92,11 +93,11 @@
           log.info("Leaving context " + httpRequest.getRequestURL());
       }
   
  -    public ReadOnlyContext getComponentContext() {
  +    public Context getComponentContext() {
           return componentContext;
       }
   
  -    public void setComponentContext(ReadOnlyContext componentContext) {
  +    public void setComponentContext(Context componentContext) {
           this.componentContext = componentContext;
       }
   }
  
  
  
  1.1                  incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebAccessLog.java
  
  Index: JettyWebAccessLog.java
  ===================================================================
  /* ====================================================================
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" and
  *    "Apache Geronimo" must not be used to endorse or promote products
  *    derived from this software without prior written permission. For
  *    written permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache",
  *    "Apache Geronimo", nor may "Apache" appear in their name, without
  *    prior written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  *
  * ====================================================================
  */
  
  
  package org.apache.geronimo.web.jetty;
  
  import java.io.File;
  import java.lang.reflect.Constructor;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.core.service.Container;
  import org.apache.geronimo.web.AbstractWebAccessLog;
  import org.mortbay.http.NCSARequestLog;
  import org.mortbay.http.RequestLog;
  import org.mortbay.jetty.Server;
  import org.mortbay.util.LifeCycle;
  
  /* -------------------------------------------------------------------------------------- */
  /**
   * JettyWebAccessLog
   * 
   * @jmx:mbean extends="org.apache.geronimo.web.AbstractWebAccessLogMBean
   * @version $Revision: 1.1 $ $Date: 2003/11/20 09:10:17 $
   */
  public class JettyWebAccessLog extends AbstractWebAccessLog implements JettyWebAccessLogMBean
  {
      private final static Log log = LogFactory.getLog(JettyWebAccessLog.class);
      private final static Class[] defaultConstructorSignature = new Class[]{};
      private final static Object[] defaultConstructorArgs = new Object[]{};
      private Server jetty = null;
      private RequestLog jettyLog = null;
      private boolean buffering = false;
      
      public JettyWebAccessLog ()
      {
          super ();
  
          try
           {
               objectName = new ObjectName ("jetty:role=WebAccessLog, instance="+hashCode());
           }
           catch (Exception e)
           {
               log.warn (e.getMessage());
           }
      }
      
   
  
      /* -------------------------------------------------------------------------------------- */
      /* Override AbstractWebAccessLog to disable
       * @param state
       * @see org.apache.geronimo.web.WebAccessLog#setResolveHostNames(boolean)
       */
      public void setResolveHostNames(boolean state)
      {
          throw new UnsupportedOperationException ("Host name DNS resolution is not supported for Jetty access log");
      }
      
      
      /* -------------------------------------------------------------------------------------- */
      /** Enable/disable buffering of logs. 
       *  Buffering improves performance.
       *  This is a Jetty-specific configuration
       * @param state true enables buffering, false disables it
       */
      public void setBuffering (boolean state)
      {
          buffering = state;
      }
      
      /* -------------------------------------------------------------------------------------- */
      /** Get buffering setting
       * This is a Jetty-specific configuration
       * @return
       */
      public boolean getBuffering ()
      {
          return buffering;
      }
      
      
  
      public ObjectName preRegister (MBeanServer server,  ObjectName objectName) throws Exception 
      {       
          return super.preRegister (server,objectName); 
      }
      
  
      /**
       * Set the parent Container for this  component
       *
       * @param container a <code>Container</code> value
       */
      public void setContainer (Container container)
      {
          super.setContainer(container);
  
          //get the Jetty instance
          if (! (container instanceof JettyWebContainer))
              throw new IllegalStateException ("Non Jetty container set as parent on JettyWebAccessLog");
  
          jetty = ((JettyWebContainer)container).getJettyServer();
      }
  
  
      public void doStart() throws Exception
     {
         try
         {
              if (getContainer() == null)
                    throw new IllegalStateException ("Container not set on JettyWebAccessLog");
             if (getLogImpl()!= null) 
             {
                 Class logImplClass = Thread.currentThread().getContextClassLoader().loadClass(getLogImpl());
                 //get the default constructor, if it has one
                 Constructor constructor = logImplClass.getConstructor (defaultConstructorSignature);
                 jettyLog = (RequestLog)constructor.newInstance (defaultConstructorArgs);
                 log.warn ("RequestLog does not support rich configuration");
                 
                 jetty.setRequestLog (jettyLog);
                 jettyLog.start();
  
                 return;
             } 
             
             log.info("Using org.mortbay.http.NCSARequestLog as log impl");
             jettyLog = new NCSARequestLog();
             NCSARequestLog ncsaLog = (NCSARequestLog)jettyLog;
             
             // set up the configuration of the access log
             ncsaLog.setBuffered(getBuffering());
             ncsaLog.setAppend (getAppend());
             ncsaLog.setRetainDays(getLogRetentionDays());
             
             if (getLogDateFormat() == null)
             {
                 log.warn ("No date format set, using Jetty default: "+ncsaLog.getLogDateFormat());
             }
             else
                 ncsaLog.setLogDateFormat (getLogDateFormat());
             
             if (getLogPattern() == null)
             {
                 log.warn ("No log pattern set, using Jetty default: NCSA common");
             }
             else if (getLogPattern().equals(NCSA_EXTENDED_PATTERN))
                 ncsaLog.setExtended (true);
             else if (!getLogPattern().equals(NCSA_COMMON_PATTERN))
             {
                 log.warn ("Jetty access log impl does not support custom patterns. Falling back to Jetty default: NCSA common");
             }
             
             if (logLocation == null)
                 throw new IllegalStateException ("No log location specified");
             
             
             File logDir = new File (logLocation.normalize());
             
             //create the directory if necessary
             if (!logDir.exists())
                logDir.mkdir();
             
             //create the filename
             String filename = (getLogPrefix() == null? "":getLogPrefix());           
             if (getLogRolloverIntervalHrs() > 0)
             {
                 log.warn ("Jetty access log does not support rollover intervals. Falling back to Jetty default: nightly ");
                 //rollover of log files is requested, so format the Jetty log file name to enable it
                 filename = filename + "yyyy_mm_dd";
             }
             else
                 filename = filename+"access";
                 
             filename =filename + (getLogSuffix() == null?"":getLogSuffix())+".log";
             ncsaLog.setFilename(logDir.getCanonicalPath()+File.separator+filename);
             
             jetty.setRequestLog(ncsaLog);
           
             ncsaLog.start();
             super.doStart();
         }
         catch (Exception e)
         {
             log.error (e);
             throw e;
         }
     }
     
     public void doStop () throws Exception 
     {
         if (jettyLog instanceof NCSARequestLog)
             jettyLog.stop();
     } 
    
  
      public RequestLog getJettyLog ()
     {
         return jettyLog;
     }
  
  }