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/09/14 14:09:44 UTC

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

janb        2003/09/14 05:09:44

  Modified:    modules/web/src/java/org/apache/geronimo/web
                        AbstractWebApplication.java
                        AbstractWebContainer.java WebApplication.java
                        WebConnector.java WebContainer.java
               modules/web/src/java/org/apache/geronimo/web/jetty
                        JettyWebConnector.java JettyWebContainer.java
  Added:       modules/web/src/java/org/apache/geronimo/web
                        AbstractWebConnector.java
               modules/web/src/java/org/apache/geronimo/web/jetty
                        JettyWebApplication.java
  Log:
  Changes in order to deploy a Jetty instance and a web connector as Geronimo services.
  
  Revision  Changes    Path
  1.7       +7 -126    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractWebApplication.java	8 Sep 2003 04:51:14 -0000	1.6
  +++ AbstractWebApplication.java	14 Sep 2003 12:09:43 -0000	1.7
  @@ -60,14 +60,9 @@
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
  -import javax.xml.parsers.FactoryConfigurationError;
  -import javax.xml.parsers.ParserConfigurationException;
  -
   import org.apache.geronimo.core.service.AbstractComponent;
   
  -import org.w3c.dom.Document;
  +
   
   /**
    * AbstractWebApplication
  @@ -83,27 +78,10 @@
        */
       private boolean java2ClassloadingCompliance = false;
   
  -    private URI webXmlURI = null;
  -
  -    private Document webXmlDoc = null;
  -    private DocumentBuilder parser = null;
  -
  -    private URI geronimoXmlURI = null;
  -    private Document geronimoXmlDoc = null;
       private Context initialContext = null;
   
       public AbstractWebApplication() {
  -        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  -        try {
  -            parser = factory.newDocumentBuilder();
  -            initialContext = new InitialContext();
  -        } catch (FactoryConfigurationError e) {
  -            throw new AssertionError("No XML parser available");
  -        } catch (ParserConfigurationException e) {
  -            throw new AssertionError("No XML parser available");
  -        } catch (NamingException e) {
  -            throw new AssertionError("No initial JNDI context");
  -        }
  +       
       }
   
       /**
  @@ -115,11 +93,7 @@
           if (getContainer() == null)
               throw new IllegalStateException("WebApplication must have a container set before START can be called");
   
  -        //probably not necessary if deployer wil do this on our behalf
  -        // set up the JNDI context for this webapp
  -        //setupENC();
  -
  -        //setupClassLoader();
  +        //setup the webapp
       }
   
       /**
  @@ -135,7 +109,7 @@
        * @see org.apache.geronimo.web.WebApplication#getServlets()
        */
       public String[] getServlets() {
  -        Document doc = getDeploymentDescriptorDocument();
  +        //TODO
           return null;
       }
   
  @@ -144,55 +118,11 @@
        * @see org.apache.geronimo.web.WebApplication#getDeploymentDescriptor()
        */
       public String getDeploymentDescriptor() {
  -        try {
  -            parseWebXml();
  -        } catch (Exception e) {
  -            throw new IllegalStateException(e.toString());
  -        }
  -        return null;
  -    }
  -
  -    /**
  -     * Get the URI of the web.xml deployment descriptor
  -     * @return
  -     * @see org.apache.geronimo.web.WebApplication#getDeploymentDescriptorURI()
  -     */
  -    public URI getDeploymentDescriptorURI() {
  -        return webXmlURI;
  -    }
  -
  -    /**
  -     * Get the Document representing the web.xml descriptor
  -     * @return
  -     * @see org.apache.geronimo.web.WebApplication#getDeploymentDescriptorDocument()
  -     */
  -    public Document getDeploymentDescriptorDocument() {
  -        //TODO - may not be required depending on deployer interface
  -        try {
  -            parseWebXml();
  -            return webXmlDoc;
  -        } catch (Exception e) {
  -            throw new IllegalStateException(e.toString());
  -        }
  -
  -    }
  -
  -
  -    //the geronimo methods may not be required, depending on the interface to the deployer
  -    public URI getGeronimoDeploymentDescriptorURI() {
  -        return geronimoXmlURI;
  -    }
  -
  -    public Document getGeronimoDeploymentDescriptorDocument() {
  -        return geronimoXmlDoc;
  -    }
  -
  -    public String getGeronimoDeploymentDescriptor() {
           //TODO
           return null;
       }
   
  -
  + 
       /**
        * Setter for classloading compliance. If true, then classloading will
        * delegate first to parent classloader a la Java2 spec. If false, then
  @@ -211,56 +141,7 @@
           return java2ClassloadingCompliance;
       }
   
  -    /**
  -     * Parse the deployment descriptor, if it hasn't been already
  -     *
  -     * @exception Exception if an error occurs
  -     */
  -    protected synchronized void parseWebXml() throws Exception {
  -        if (webXmlURI == null) {
  -            return;
  -        }
  -        if (webXmlDoc != null) {
  -            return;
  -        }
  -
  -        webXmlDoc = parser.parse(webXmlURI.toString());
  -    }
  -
  -    protected synchronized void parseGeronimoXml() throws Exception {
  -        if (geronimoXmlURI == null) {
  -            return;
  -        }
  -        if (geronimoXmlDoc != null) {
  -            return;
  -        }
  -
  -        geronimoXmlDoc = parser.parse(geronimoXmlURI.toString());
  -    }
  -
  -    /*
  -        protected void setupENC() throws Exception
  -        {
  -            //parse the standard descriptor
  -            parseWebXml();
  -
  -            //parse the geronimo web descriptor?
  -            parseGeronimoXml();
  -
  -            //create the java:comp/env context
  -            Context enc = null;
  -
  -            //populate the resources
  -
  -            //populate the ejbs
  -
  -            //populate the UserTransaction
  -            enc.bind ("UserTransaction",  new LinkRef ("javax.transaction.UserTransaction"));
  -
  -            //populate the security
   
  -            //secure the context as read-only (if necessary)
   
  -        }
  -        */
  +  
   }
  
  
  
  1.8       +360 -32   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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractWebContainer.java	8 Sep 2003 04:51:14 -0000	1.7
  +++ AbstractWebContainer.java	14 Sep 2003 12:09:43 -0000	1.8
  @@ -56,23 +56,60 @@
   
   package org.apache.geronimo.web;
   
  -import java.net.URI;
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
   
  +import java.io.InputStream;
  +import java.io.IOException;
  +import java.net.URI;
  +import java.net.URL;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.HashSet;
  +import java.util.Set;
  +import javax.management.Attribute;
  +import javax.management.AttributeNotFoundException;
  +import javax.management.InstanceNotFoundException;
  +import javax.management.MBeanException;
  +import javax.management.MBeanInfo;
  +import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanOperationInfo;
  +import javax.management.MBeanRegistration;
  +import javax.management.MBeanServer;
  +import javax.management.MBeanServerNotification;
  +import javax.management.MalformedObjectNameException;
  +import javax.management.Notification;
  +import javax.management.ObjectName;
  +import javax.management.ReflectionException;
  +import javax.management.relation.RelationServiceMBean;
  +import javax.management.relation.Role;
   import org.apache.geronimo.core.service.AbstractContainer;
   import org.apache.geronimo.core.service.Component;
  -
  +import org.apache.geronimo.core.service.Container;
  +import org.apache.geronimo.kernel.deployment.DeploymentException;
  +import org.apache.geronimo.kernel.deployment.goal.DeployURL;
  +import org.apache.geronimo.kernel.deployment.goal.DeploymentGoal;
  +import org.apache.geronimo.kernel.deployment.goal.RedeployURL;
  +import org.apache.geronimo.kernel.deployment.goal.UndeployURL;
  +import org.apache.geronimo.kernel.deployment.DeploymentPlan;
  +import org.apache.geronimo.kernel.deployment.scanner.URLType;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.w3c.dom.Document;
  +import org.w3c.dom.Node;
  +
   
   /**
    * AbstractWebContainer
    *
    * Base class for web containers.
  - *
  + * @jmx:mbean extends="org.apache.geronimo.kernel.deployment.DeploymentPlanner, org.apache.geronimo.web.WebContainer, org.apache.geronimo.kernel.management.StateManageable, javax.management.MBeanRegistration" 
    * @version $Revision$ $Date$
    */
  -public abstract class AbstractWebContainer extends AbstractContainer implements WebContainer {
  +public abstract class AbstractWebContainer
  +    extends AbstractContainer
  +    implements WebContainer, AbstractWebContainerMBean, MBeanRegistration
  +{
  +    private final static Log log = LogFactory.getLog(AbstractWebContainer.class);
  +
       /**
        * Location of the default web.xml file
        */
  @@ -83,25 +120,328 @@
        */
       private Document defaultWebXmlDoc = null;
   
  +    
  +   
  +
  +    /* -------------------------------------------------------------------------------------- */
       /**
  -     * Controls unpacking of wars to tmp runtime location
  +     *  Constructor
        */
  -    private boolean unpackWars = true;
  +    public AbstractWebContainer()
  +    {   
  +    }
   
  -    private final DocumentBuilder parser;
   
       /**
  -     * Constructor
  +     * Get our mbean name from a pre-registration call.
  +     *
  +     * @param mBeanServer a <code>MBeanServer</code> value
  +     * @param objectName an <code>ObjectName</code> value
  +     * @return an <code>ObjectName</code> value
  +     * @exception Exception if an error occurs
  +     */
  +   public ObjectName preRegister(MBeanServer server, ObjectName objectName) 
  +       throws Exception 
  +    
  +    {
  +        return super.preRegister(server, objectName);
  +    }
  +
  +
  +    /**
  +     * Establish this webcontainer as a deployment planner
  +     *
  +     * @param aBoolean a <code>Boolean</code> value
        */
  -    public AbstractWebContainer() {
  -        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +    public void postRegister(Boolean aBoolean) {
           try {
  -            parser = factory.newDocumentBuilder();
  +            super.postRegister(aBoolean);
  +            List planners = relationService.getRole("DeploymentController-DeploymentPlanner", "DeploymentPlanner");
  +
  +            planners.add(objectName);
  +            relationService.setRole("DeploymentController-DeploymentPlanner",
  +                                    new Role("DeploymentPlanner", planners));
  +            log.trace ("Registered WebContainer as a DeploymentPlanner");
           } catch (Exception e) {
  -            throw new AssertionError("No XML parser available");
  +
  +            log.error ("XX: ", e);
  +
  +            IllegalStateException e1 = new IllegalStateException();
  +            e1.initCause(e);
  +            throw e1;
           }
       }
   
  +
  +    /**
  +     * Do nothing for now
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    public void preDeregister() throws Exception {
  +    }
  +
  +
  +
  +    /**
  +     * Do nothing for now
  +     *
  +     */
  +    public void postDeregister() {
  +    }
  +
  +
  +    /**
  +     * Monitor JMX notifications to find Web components
  +     *
  +     * @param n a <code>Notification</code> value
  +     * @param o an <code>Object</code> value
  +     */
  +    public void handleNotification(Notification n, Object o) 
  +    {
  +        ObjectName source = null;
  +
  +        try
  +        {        
  +            //check for registrations of web connectors and web logs
  +            if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(n.getType())) 
  +            {
  +                MBeanServerNotification notification = (MBeanServerNotification) n;
  +                source = notification.getMBeanName();
  +                if (server.isInstanceOf (source, WebConnector.class.getName()))
  +                {
  +                    log.debug ("Received registration notification for webconnecter="+source);
  +
  +      
  +
  +                    // set up the Container on the Connector to be us
  +                    // this will result in the Connector adding itself to
  +                    // our containment hierarchy
  +                    server.setAttribute (source, 
  +                                         new Attribute ("Container",
  +                                                        (Container)this));
  +                }
  +                else if (server.isInstanceOf (source, WebAccessLog.class.getName()))
  +                {
  +                    // set up the Container on the WebAccessLog to be us
  +                    // this will result in the WebAccessLog adding itself to
  +                    // our containment hierarchy
  +                    server.invoke (source, 
  +                                   "setContainer", new Object[]{this},
  +                                   new String[]{"org.apache.geronimo.core.service.Container" });
  +                }
  +            }
  +        }
  +        catch (InstanceNotFoundException e)
  +        {
  +            log.debug ("Registration notification received for non-existant object: "+ source);
  +        }
  +        catch (MBeanException e)
  +        {
  +            throw new IllegalStateException (e.toString());
  +        }
  +        catch (ReflectionException e)
  +        {
  +            throw new IllegalStateException (e.toString());
  +        }
  +        catch (Exception e)
  +        {
  +            throw new IllegalStateException (e.toString());
  +        }
  +
  +        super.handleNotification (n, o);
  +    }
  +
  +
  +
  +
  +
  +    /**
  +     * Deploy/redeploy/undeploy a webapplication
  +     *
  +     * @param goals a <code>Set</code> value
  +     * @param plans a <code>Set</code> value
  +     * @return a <code>boolean</code> value
  +     * @exception DeploymentException if an error occurs
  +     */
  +    public boolean plan(Set goals, Set plans) throws DeploymentException
  +    {
  +        boolean progress = false;
  +        Set x = new HashSet(goals);
  +        for (Iterator i = x.iterator(); i.hasNext();) {
  +            DeploymentGoal goal = (DeploymentGoal) i.next();
  +            if (goal instanceof DeployURL) {
  +                progress = deploy((DeployURL) goal, goals, plans);
  +            } else if (goal instanceof RedeployURL) {
  +                progress = redeploy((RedeployURL) goal, goals);
  +            } else if (goal instanceof UndeployURL) {
  +                progress = remove((UndeployURL) goal, goals, plans);
  +            }
  +        }
  +        return progress;
  +    }
  +
  +
  +
  +    /**
  +     * Fresh deployment to handle
  +     *
  +     * @param goal a <code>DeployURL</code> value
  +     * @param goals a <code>Set</code> value
  +     * @param plans a <code>Set</code> value
  +     * @return a <code>boolean</code> value
  +     * @exception DeploymentException if an error occurs
  +     */
  +    public  boolean deploy (DeployURL goal, Set goals, Set plans) throws DeploymentException {
  +        InputStream is;
  +        URL url = goal.getUrl();
  +        URI baseURI = URI.create(url.toString()).normalize();;
  +
  +        URLType type = goal.getType();
  +        URL webXmlURL = null;
  + 
  +
  +        // this won't work for ear deployments where the application.xml
  +        // specifies a contextpath - how do we get it?
  +
  +        if (type == URLType.PACKED_ARCHIVE) 
  +        {
  +            //check it ends with ".war" 
  +            if (!url.getPath().endsWith(".war"))
  +                return false;
  +
  +            InputStream stream = null;
  +            try
  +            {
  +                URL webInfURL = new URL (url, "WEB-INF");
  +                stream = webInfURL.openStream();
  +            }
  +            catch (IOException e) 
  +            {
  +                throw new DeploymentException("Failed to open stream for URL: " + url, e);
  +            }
  +            finally
  +            {
  +                try
  +                {
  +                    if (stream != null)
  +                        stream.close();
  +                }
  +                catch (IOException iox)
  +                {
  +                    throw new DeploymentException ("Failed to close stream for URL: "+url, iox);
  +                }
  +            }
  +        }
  +        else if (type == URLType.UNPACKED_ARCHIVE) 
  +        {
  +            // check if there is a WEB-INF
  +            InputStream stream = null;
  +            try
  +            {
  +                URL webInfURL = new URL (url, "WEB-INF");
  +                stream = webInfURL.openStream();
  +            }
  +            catch (IOException e) 
  +            {
  +                throw new DeploymentException("Failed to open stream for URL: " + url, e);
  +            }
  +            finally
  +            {
  +                try
  +                {
  +                    if (stream != null)
  +                        stream.close();
  +                }
  +                catch (IOException iox)
  +                {
  +                    throw new DeploymentException ("Failed to close stream for URL: "+url, iox);
  +                }
  +            }
  +        } 
  +        else 
  +        {
  +            //we can't deploy any other structure
  +            return false;
  +        }
  +
  +        //check to see if the webapp has already been deployed
  +        ObjectName deploymentName = null;
  +        try 
  +        {
  +            deploymentName = new ObjectName("geronimo.deployment:role=DeploymentUnit,type=WebApplication,url=" 
  +                                            + ObjectName.quote(url.toString()));
  +        } 
  +        catch (MalformedObjectNameException e) 
  +        {
  +            throw new DeploymentException(e);
  +        }
  +
  +        if (server.isRegistered(deploymentName))
  +            throw new DeploymentException ("Web app already deployed at URL:"+url);
  +
  +        // steps in the deployment plan for a web container are:
  +        //   1. create web app
  +        //   2. create class loader and set it for the webapp
  +        //   3. setup enc and set it for the webapp
  +        //   4. start the webapp?
  +      
  +     
  +        // create a webapp typed to the concrete type of the web container
  +        WebApplication webapp = createWebApplication ();
  +
  +
  +        //do the config setup of the webapp
  +        //NB. it would be nice to use the ServiceDeploymentPlanner to
  +        //do these - look into setting up appropriate MetaData etc
  +        //to call it on the fly
  +        
  +        //need to set the URI on the webapp
  +        URI webappURI = null;
  +        webapp.setURI (webappURI);
  +
  +
  +        //contextPath can come from:
  +        //  application.xml
  +        //  geronimo-web.xml
  +        //  name of the war (without .war extension) or webapp dir
  +
  +        String contextPath = null;
  +        webapp.setContextPath(contextPath);
  +
  +        // How do we identify which is the parent classloader???
  +        webapp.setParentClassLoader (Thread.currentThread().getContextClassLoader());
  +
  +        //when to add the webapp??
  +        addComponent (webapp);
  +
  +
  +        // Create a deployment plan
  +        DeploymentPlan deploymentUnitPlan = new DeploymentPlan();
  +
  +        // add a task to start the webapp which will finish configuring it
  +        //NB: is this OK? What happens if start task gets called after webapp already started?
  +        //deploymentUnitPlan.addTask (new StartWebAppTask (server, this, webapp, deploymentName));
  +        plans.add (deploymentUnitPlan);
  +        
  +        goals.remove(goal);
  +        return true;
  +    }
  +
  +
  +    // TODO
  +    private boolean remove(UndeployURL goal, Set goals, Set plans) throws DeploymentException {
  +        return true;
  +    }
  +
  +    // TODO
  +    private boolean redeploy(RedeployURL goal, Set goals) throws DeploymentException {
  +      
  +        return true;
  +    }
  +
  +
  +    /* -------------------------------------------------------------------------------------- */
       /**
        * Creates a WebApplication from the url and associates it with this container.
        * @param url the location of the web application to deploy
  @@ -145,8 +485,11 @@
        * Set a uri of a web.xml containing defaults for this container.
        * @param uri the location of the default web.xml file
        */
  -    public void setDefaultWebXmlURI(URI uri) {
  +    public void setDefaultWebXmlURI(URI uri)
  +    {
  +        log.debug ("DefaultWebXmlURI="+(uri==null?"null":uri.toString()));
           defaultWebXmlURI = uri;
  +        
       }
   
       /**
  @@ -165,26 +508,10 @@
           if (defaultWebXmlURI == null)
               return;
   
  -        defaultWebXmlDoc = parser.parse(defaultWebXmlURI.toString());
  +        //defaultWebXmlDoc = parser.parse(defaultWebXmlURI.toString());
       }
   
  -    /**
  -     * @return
  -     * @see org.apache.geronimo.web.WebContainer#getUnpackWars()
  -     */
  -    //public boolean getUnpackWars()
  -    //{
  -    //    return unpackWars;
  -    //}
   
  -    /**
  -     * @param state
  -     * @see org.apache.geronimo.web.WebContainer#setUnpackWars(boolean)
  -     */
  -    //public void setUnpackWars(boolean state)
  -    //{
  -    //    unpackWars = state;
  -    //}
   
       /**
        * Add a component to this container's containment hierarchy
  @@ -221,6 +548,7 @@
        * @param connector
        */
       protected void webConnectorAdded(WebConnector connector) {
  +     
       }
   
       /**
  
  
  
  1.7       +13 -18    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WebApplication.java	8 Sep 2003 04:51:14 -0000	1.6
  +++ WebApplication.java	14 Sep 2003 12:09:43 -0000	1.7
  @@ -77,8 +77,12 @@
       public URI getURI();
   
       public void setURI(URI uri);
  +    
  +    public void setParentClassLoader (ClassLoader loader);
   
  +    public ClassLoader getParentClassLoader ();
   
  +    /*-------------------------------------------------------------------------------- */
       /**
        * JSR077 WebModule method to expose the
        * names of all servlets contained within this webapp.
  @@ -92,23 +96,14 @@
       public void setContextPath(String path);
   
       public String getDeploymentDescriptor();
  -
  -    public URI getDeploymentDescriptorURI();
  -
  -    public Document getDeploymentDescriptorDocument();
  -
  -    public String getGeronimoDeploymentDescriptor();
  -
  -    public URI getGeronimoDeploymentDescriptorURI();
  -
  -    public Document getGeronimoDeploymentDescriptorDocument();
  -
  -    /**
  -     * Getter for the class loader delegation model for this webapp
  -     * @return
  -     */
  -    public boolean getJava2ClassloadingCompliance();
  -
  +    
  +    /* -------------------------------------------------------------------------------------- */
  +     /**Getter for the class loader delegation model for this webapp
  +      * @return
  +      */
  +     public boolean getJava2ClassloadingCompliance ();
  +     
  +    /* -------------------------------------------------------------------------------------- */
       /**
        * Set the class loading delegation model for this web application
        * @param state
  
  
  
  1.4       +7 -1      incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebConnector.java
  
  Index: WebConnector.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebConnector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebConnector.java	8 Sep 2003 04:51:14 -0000	1.3
  +++ WebConnector.java	14 Sep 2003 12:09:43 -0000	1.4
  @@ -113,4 +113,10 @@
       public void setContexts(String[] contexts);
   
       public String[] getContexts();
  +
  +/*
  +  Report the state of the listener: handling connections, bleeding connections etc
  +    public HandlingState getHandlingState ();
  +
  +*/
   }
  
  
  
  1.6       +1 -14     incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebContainer.java
  
  Index: WebContainer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebContainer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WebContainer.java	8 Sep 2003 04:51:14 -0000	1.5
  +++ WebContainer.java	14 Sep 2003 12:09:43 -0000	1.6
  @@ -97,17 +97,4 @@
        */
       public Document getDefaultWebXmlDoc();
   
  -    /**
  -     * Control if wars will be unpacked to temporary location or not
  -     * @param state
  -     * @todo this might be handled by the deployer instead
  -     */
  -    //public void setUnpackWars (boolean state);
  -
  -    /**
  -     * Getter for whether wars will be unpacked to temporary location or not
  -     * @return
  -     * @todo this might be handled by the deployer instead
  -     */
  -    //public boolean getUnpackWars ();
   }
  
  
  
  1.1                  incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebConnector.java
  
  Index: AbstractWebConnector.java
  ===================================================================
  package org.apache.geronimo.web;
  
  import org.apache.geronimo.core.service.AbstractComponent;
  import org.apache.geronimo.core.service.Container;
  import java.util.Arrays;
  import java.util.List;
  
  
  /**
   * AbstractWebConnector.java
   *
   *
   * Created: Mon Sep  8 20:39:02 2003
   * @jmx:mbean extends="org.apache.geronimo.web.WebConnector, org.apache.geronimo.kernel.management.StateManageable"
   * @author <a href="mailto:janb@mortbay.com">Jan Bartel</a>
   * @version 1.0
   */
  public abstract class AbstractWebConnector extends AbstractComponent implements WebConnector, AbstractWebConnectorMBean
  {
      
      public static final String HTTP_PROTOCOL = "http";
      public static final String HTTPS_PROTOCOL = "https";
      public static final String AJP13_PROTOCOL = "ajp13";
  
      private int _port = 0;
      private String _protocol = null;
      private String _interface = null;
      private int _maxConnections = 0;
      private int _maxIdleTime = 0;
      private List _contexts = null;
  
  
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setPort(int)
       */
      public void setPort(int port)
      {
          _port = port;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getPort()
       */
      public int getPort()
      {
          return _port;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setProtocol(java.lang.String)
       */
      public void setProtocol(String protocol)
      {
          _protocol = protocol;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getProtocol()
       */
      public String getProtocol()
      {
          return _protocol;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setInterface(java.lang.String)
       */
      public void setInterface(String iface)
      {
          _interface = iface;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getInterface()
       */
      public String getInterface()
      {
          return _interface;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setMaxConnections(int)
       */
      public void setMaxConnections(int maxConnects)
      {
          _maxConnections = maxConnects;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getMaxConnections()
       */
      public int getMaxConnections()
      {
          return _maxConnections;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setMaxIdleTime(int)
       */
      public void setMaxIdleTime(int maxIdleTime)
      {
          _maxIdleTime = maxIdleTime;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getMaxIdleTime()
       */
      public int getMaxIdleTime()
      {
          return _maxIdleTime;
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#setContexts(java.lang.String[])
       */
      public void setContexts(String[] contexts)
      {
          _contexts = Arrays.asList(contexts);
      }
  
      /* (non-Javadoc)
       * @see org.apache.geronimo.web.WebConnector#getContexts()
       */
      public String[] getContexts()
      {
          return (String[])_contexts.toArray(new String[0]);
      }
      
  
      public void setContainer (Container container)
      {
          super.setContainer(container);
          
          container.addComponent (this);
      }
    
      protected void doStart() throws Exception
      {
          if (getContainer() == null)
              throw new IllegalStateException ("Connector has no web container");
  
      }
  
  } // AbstractWebConnector
  
  
  
  1.4       +179 -98   incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebConnector.java
  
  Index: JettyWebConnector.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebConnector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JettyWebConnector.java	8 Sep 2003 04:51:14 -0000	1.3
  +++ JettyWebConnector.java	14 Sep 2003 12:09:44 -0000	1.4
  @@ -56,110 +56,191 @@
   
   package org.apache.geronimo.web.jetty;
   
  +import java.lang.reflect.Constructor;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.core.service.AbstractComponent;
  +import org.apache.geronimo.core.service.Container;
  +import org.apache.geronimo.kernel.management.State;
  +import org.apache.geronimo.web.AbstractWebConnector;
   import org.apache.geronimo.web.WebConnector;
  -
   import org.mortbay.http.HttpListener;
  +import org.mortbay.http.SocketListener;
  +import org.mortbay.http.SunJsseListener;
  +import org.mortbay.http.ajp.AJP13Listener;
  +import org.mortbay.util.ThreadedServer;
  +import org.mortbay.jetty.Server;
   
   /**
  + * @jmx:mbean extends="org.apache.geronimo.web.AbstractWebConnectorMBean"
    * @version $Revision$ $Date$
    */
  -public class JettyWebConnector extends AbstractComponent implements WebConnector {
  -    private HttpListener listener;
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setPort(int)
  -     */
  -    public void setPort(int port) {
  -        listener.setPort(port);
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getPort()
  -     */
  -    public int getPort() {
  -        return listener.getPort();
  +public class JettyWebConnector extends AbstractWebConnector implements JettyWebConnectorMBean
  +{
  +    private final static Log log = LogFactory.getLog(JettyWebConnector.class);
  +    private final static Class[] _defaultConstructorSignature = new Class[]{};
  +    private final static Object[] _defaultConstructorArgs = new Object[]{};
  +    private HttpListener _listener = null;
  +    private Server _jetty = null;
  +
  +
  +
  +    /**
  +     * 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 connector");
  +
  +        _jetty = ((JettyWebContainer)container).getJettyServer();
  +    }
  +
  +
  +    /**
  +     * Set up the port for the Connector to listen on.
  +     * It is not permitted to change the port if the
  +     * connector is in operation.
  +     *
  +     * @param port an <code>int</code> value
  +     */
  +    public void setPort (int port)
  +    {
  +        if (getStateInstance() != State.STOPPED) 
  +            throw new IllegalStateException ("Cannot change the connector port after the connector is started");
  +
  +        super.setPort(port);
  +    }
  +
  +
  +    /**
  +     *  Set up the protocol for the connector.
  +     * It is not permitted to change the protocol if
  +     * the connector is operating.
  +     *
  +     * @param protocol a <code>String</code> value
  +     */
  +    public void setProtocol (String protocol)
  +    {
  +         if (getStateInstance() != State.STOPPED) 
  +            throw new IllegalStateException ("Cannot change protocol after connector has started");
  +
  +        super.setProtocol(protocol);
  +    }
  +
  +
  +    /**
  +     * Set up the host/interface to listen on.
  +     * It is not permitted to change this once the
  +     * connector has started.
  +     *
  +     * @param iface a <code>String</code> value
  +     */
  +    public void setInterface (String iface)
  +    {     
  +        if (getStateInstance() != State.STOPPED) 
  +            throw new IllegalStateException ("Cannot change interface after connector has started");
  +        super.setInterface(iface);
  +    }
  +
  +    /**
  +     * Start the connector
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    public void doStart() throws Exception
  +    {
  +        try
  +        {
  +        if (getContainer() == null)
  +            throw new IllegalStateException ("Container not set on connector");
  +
  +        //configure the listener 
  +        if ((getProtocol() == null) || (getProtocol().equalsIgnoreCase(HTTP_PROTOCOL)))
  +        {
  +            _listener = new SocketListener();
  +        }      
  +        else if (getProtocol().equalsIgnoreCase (AJP13_PROTOCOL))
  +        {
  +            _listener = new AJP13Listener();
  +        }
  +        else if (getProtocol().equalsIgnoreCase (HTTPS_PROTOCOL))
  +        {
  +            _listener = new SunJsseListener();
  +        }
  +        else
  +        {
  +            //maybe the protocol is a classname of a listener 
  +            //implementing a particular protocol
  +            Class listenerClass = Thread.currentThread().getContextClassLoader().loadClass(getProtocol());
  +            //get the default constructor, if it has one
  +            Constructor constructor = listenerClass.getConstructor (_defaultConstructorSignature);
  +            _listener = (HttpListener)constructor.newInstance (_defaultConstructorArgs);
  +        }
  +
  +        log.debug ("About to start WebConnector: "+getObjectName());
  +        //NB: need to check if port is set - what to use instead of 0?
  +        _listener.setPort(getPort());
  +
  +        if (getInterface() != null)
  +            _listener.setHost(getInterface());
  +
  +        //take the listener default unless connections have been set
  +        //what to use instead of 0?
  +        if (getMaxConnections() > 0)
  +            ((ThreadedServer)_listener).setMaxThreads(getMaxConnections());
  +
  +        //take the listener default unless idle time has been set
  +        //what to use instead of 0?
  +        if (getMaxIdleTime() > 0)
  +            ((ThreadedServer)_listener).setMaxIdleTimeMs (getMaxIdleTime());
  +
  +        //open the underlying Jetty socket, if these calls fail,
  +        //the connector will not transit to STARTED
  +        ((ThreadedServer)_listener).open();
  +        ((ThreadedServer)_listener).start();
  +        log.debug ("Listener on port="+getPort()+" started.");
  +
  +        //at this point, when the method returns, the WebConnector will be STARTED
  +        //even though the underlying socket may not be handling
  +        //connections because it's criteria to listen may not
  +        //be met etc
  +        
  +        //if the start succeeded, set up the listener on the
  +        //Jetty instance
  +        _jetty.addListener(_listener);
  +        log.debug ("Listener on port="+getPort()+" added to Jetty");
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            throw e;
  +        }
  +    }
  +
  +  
  +    /**
  +     * Stop the connector
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    public void doStop () throws Exception
  +    {
  +        _listener.stop();
  +    }
  +
  +    /**
  +     * Get the underlying Jetty listener
  +     *
  +     * @return the Jetty listener
  +     */
  +    HttpListener getListener ()
  +    {
  +        return _listener;
       }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setProtocol(java.lang.String)
  -     */
  -    public void setProtocol(String protocol) {
  -        // TODO. We have a choice here - if the protocol changes then create a new listener
  -        // and copy over all the parameters from the old listener  OR this class can store all the
  -        // parameters and only create a listener when it is started.
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getProtocol()
  -     */
  -    public String getProtocol() {
  -        // TODO Auto-generated method stub
  -        return null;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setInterface(java.lang.String)
  -     */
  -    public void setInterface(String iface) {
  -        // TODO Auto-generated method stub
  -
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getInterface()
  -     */
  -    public String getInterface() {
  -        // TODO Auto-generated method stub
  -        return null;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setMaxConnections(int)
  -     */
  -    public void setMaxConnections(int maxConnects) {
  -        // TODO Auto-generated method stub
  -
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getMaxConnections()
  -     */
  -    public int getMaxConnections() {
  -        // TODO Auto-generated method stub
  -        return 0;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setMaxIdleTime(int)
  -     */
  -    public void setMaxIdleTime(int maxIdleTime) {
  -        // TODO Auto-generated method stub
  -
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getMaxIdleTime()
  -     */
  -    public int getMaxIdleTime() {
  -        // TODO Auto-generated method stub
  -        return 0;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#setContexts(java.lang.String[])
  -     */
  -    public void setContexts(String[] contexts) {
  -        // TODO Auto-generated method stub
  -
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.geronimo.web.WebConnector#getContexts()
  -     */
  -    public String[] getContexts() {
  -        // TODO Auto-generated method stub
  -        return null;
  -    }
  -
   }
  
  
  
  1.5       +99 -5     incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebContainer.java
  
  Index: JettyWebContainer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebContainer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JettyWebContainer.java	8 Sep 2003 04:51:14 -0000	1.4
  +++ JettyWebContainer.java	14 Sep 2003 12:09:44 -0000	1.5
  @@ -56,18 +56,112 @@
   
   package org.apache.geronimo.web.jetty;
   
  +import java.net.URI;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.geronimo.core.service.Container;
  +import org.apache.geronimo.kernel.management.StateManageable;
   import org.apache.geronimo.web.AbstractWebContainer;
   import org.apache.geronimo.web.WebApplication;
  +import org.apache.geronimo.web.WebConnector;
  +import org.mortbay.jetty.Server;
  +import org.mortbay.http.SocketListener;
   
   /**
    * Base class for jetty web containers.
  + * @jmx:mbean extends="org.apache.geronimo.web.AbstractWebContainerMBean"
  + *
    *
    * @version $Revision$ $Date$
    */
  -public class JettyWebContainer extends AbstractWebContainer {
  +public class JettyWebContainer extends AbstractWebContainer implements JettyWebContainerMBean {
  +  
  +    private final Log _log = LogFactory.getLog(JettyWebContainer.class);
  +
  +    private Server _jettyServer = null;
  +
  +
  +    public JettyWebContainer ()
  +    {
  +        _jettyServer = new Server();
  +    }
  +
  +
  +    /**
  +     * Start the Jetty server
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    public void doStart() throws Exception
  +    {
  +        try
  +        {
  +            _log.debug ("Jetty Server starting");
  +            
  +            _jettyServer.start();
  +
  +            _log.debug ("Jetty Server started");
  +        }
  +        catch (Exception e)
  +        {
  +            _log.error ("Exception in doStart()", e);
  +        }
  +    }
  +
  + 
  +    public WebApplication createWebApplication ()
  +    { 
  +        return new JettyWebApplication();
  +    }
   
  -    public WebApplication createWebApplication() {
  -        //TODO
  -        return null;
  + 
  +
  +    /**
  +     * Get the Jetty server delegate
  +     *
  +     * @return the Jetty server
  +     */
  +    Server getJettyServer ()
  +    {
  +        return _jettyServer;
  +    }
  +
  +
  +    
  +    /**
  +     * Handle addition of a web connector.
  +     *
  +     * @param connector a <code>WebConnector</code> value
  +     */
  +    protected void webConnectorAdded(WebConnector connector)
  +    {
  +        _log.debug ("Web connector="+connector.getObjectName()+" added");
  +        super.webConnectorAdded(connector);
       }
  +
  +
  +
  +
  +    /**
  +     * Handle removal of a web connector
  +     *
  +     * @param connector a <code>WebConnector</code> value
  +     */
  +    protected void webConnectorRemoved (WebConnector connector)
  +    {
  +        try
  +        {
  +            //stop the connector
  +            if (connector instanceof StateManageable)
  +                ((StateManageable)connector).stop();
  +        }
  +        catch (Exception e)
  +        {
  +            _log.warn("Ignoring exception on stopping connector", e);
  +        }
  +
  +        //remove the listener
  +        _jettyServer.removeListener (((JettyWebConnector)connector).getListener());
  +    }
  +
   }
  
  
  
  1.1                  incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java
  
  Index: JettyWebApplication.java
  ===================================================================
  package org.apache.geronimo.web.jetty;
  
  import java.net.URI;
  import org.apache.geronimo.core.service.AbstractComponent;
  import org.apache.geronimo.kernel.management.State;
  import org.apache.geronimo.web.WebApplication;
  import org.mortbay.jetty.servlet.WebApplicationContext;
  
  
  
  /**
   * JettyWebApplication.java
   *
   *
   * Created: Sun Sep 14 16:40:17 2003
   *
   * @author <a href="mailto:janb@mortbay.com">Jan Bartel</a>
   * @version 1.0
   */
  public class JettyWebApplication extends AbstractComponent implements WebApplication
  {
      private WebApplicationContext _jettyContext = null;
      private URI _uri = null;
  
  
      public JettyWebApplication() 
      {
          _jettyContext = new WebApplicationContext();
      }
      
      
      public void setURI (URI uri)
      {
          _uri = uri;
          _jettyContext.setWAR (_uri.toString());
      }
      
      public URI getURI ()
      {
          return _uri;
      }
  
      public void setParentClassLoader (ClassLoader loader)
      {
          _jettyContext.setParentClassLoader (loader);
      }
  
      public ClassLoader getParentClassLoader()
      {
          return _jettyContext.getParentClassLoader();
      }
  
  
      public String[] getServlets ()
      {
          //TODO
          return null;
      }
  
      public void setContextPath (String path)
      {
          _jettyContext.setContextPath(path);
      }
  
      public String getContextPath ()
      {
          return _jettyContext.getContextPath();
      }
  
  
      public String getDeploymentDescriptor ()
      {
          //TODO
          return null;
      }
  
  
  
      public boolean getJava2ClassloadingCompliance ()
      {
          return _jettyContext.isClassLoaderJava2Compliant();
      }
  
      public void setJava2ClassloadingCompliance (boolean state)
      {
          _jettyContext.setClassLoaderJava2Compliant(state);
      }
  
  
      WebApplicationContext getJettyContext ()
      {
          return _jettyContext;
      }
  }