User: jules_gosnell
  Date: 01/05/18 15:01:38

  Modified:    jetty/src/main/org/jboss/jetty Jetty.java JettyService.java
                        JettyServiceMBean.java
  Log:
  move onto Scott's AbstractWebContainer and add support for ENC stuff
  
  Revision  Changes    Path
  1.4       +96 -118   contrib/jetty/src/main/org/jboss/jetty/Jetty.java
  
  Index: Jetty.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/Jetty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Jetty.java        2001/05/08 23:02:30     1.3
  +++ Jetty.java        2001/05/18 22:01:38     1.4
  @@ -11,149 +11,80 @@
    
   package org.jboss.jetty;
   
  -import java.util.Hashtable;
  -import java.util.Vector;
  -import java.net.URL;
  -import org.jboss.ejb.DeploymentException;
   import com.mortbay.Jetty.Servlet.WebApplicationContext;
  -import com.mortbay.HTTP.HandlerContext;
   import com.mortbay.Util.Code;
   import com.mortbay.Util.Log;
  +import com.mortbay.Util.Resource;
   import com.mortbay.XML.XmlConfiguration;
   import com.mortbay.XML.XmlParser;
   
  -import org.xml.sax.SAXException;
  -import org.xml.sax.Attributes;
  +import java.io.*;
  +import java.net.URL;
  +import java.util.Hashtable;
   
  -import javax.naming.Context;
  -import javax.naming.InitialContext;
  -import java.lang.reflect.Method;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   
  -abstract class JndiHandler
  -  extends org.xml.sax.helpers.DefaultHandler
  -{
  -  String _tmp;                       // temporary buffer
  +import org.jboss.ejb.DeploymentException;
   
  -  public void
  -    startElement (String uri, String localName, String qName, Attributes attrs)
  -    throws SAXException
  -  {
  -    _tmp="";
  -  }
  +import org.jboss.web.WebApplication;
   
  -  // is this how it should be done ?
  -  public void
  -    characters (char[] buf, int offset, int len)
  -    throws SAXException
  -  {
  -    _tmp+=new String(buf,offset,len);
  -  }
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
   
  -  public void
  -    endElement(String uri, String localName, String qName)
  -    throws SAXException
  +class JettyResolver
  +  implements EntityResolver 
  +{
  +  protected Hashtable _table=new Hashtable();
  +
  +  public InputSource
  +    resolveEntity (String publicId, String systemId)
     {
  +    System.err.println("resolving "+publicId+" : "+systemId);
       
  -    String methodName="set_"+localName.replace('-','_').toLowerCase();
  -    Class[] params={_tmp.getClass()};
  +    URL url=(URL)_table.get(publicId);
       
  -    try
  +    if (url==null)
       {
  -      Method method=getClass().getMethod(methodName,params);
  -      Object[] args={_tmp};
  -      method.invoke(this, args);
  +      System.err.println("no resolution for "+publicId);
       }
  -    catch(NoSuchMethodException e)
  +    else
       {
  -      Log.warning("NYI: tag - "+localName+" ("+methodName+")");
  +      System.err.println("resolved "+publicId+" : "+url);
  +      try
  +      {
  +     InputSource is=new InputSource(url.openConnection().getInputStream());
  +     return is;
  +      }
  +      catch (IOException e)
  +      {
  +     System.err.println("bad resolution "+publicId+" : "+url);
  +      }
       }
  -    catch(Exception e)
  -    {
  -      e.printStackTrace();
  -    }
  -  }
  -  
  -  public void
  -    doBinding(String from, String to)
  -  {
  -    Log.event("binding: "+from+" to "+to);
  -  }
  -  
  -  static
  -  {
  -    // ensure comp/env context exists...
  -    try
  -    {
  -      Context context = (Context)(new InitialContext().lookup("java:comp"));
  -      context = context.createSubcontext("env");
   
  -      Log.event("Ensured existence of java:comp/env subcontext");
  -    }
  -    catch(Exception exception)
  -    {
  -      exception.printStackTrace();
  -    }
  +    return null;
     }
  -}
   
  -// The ejb-ref element is used to declare a reference to an enterprise
  -// bean.
  -
  -class EJBRefHandler extends JndiHandler
  -{
  -  // The ejb-ref-name element contains the name of an EJB
  -  // reference. This is the JNDI name that the servlet code uses to
  -  // get a reference to the enterprise bean.
  -  String _ejbRefName;
  -  // The ejb-ref-type element contains the expected java class type of
  -  // the referenced EJB.
  -  String _ejbRefType;
  -  // The ejb-home element contains the fully qualified name of the
  -  // EJB's home interface.
  -  String _home;
  -  //  The ejb-remote element contains the fully qualified name of the
  -  //  EJB's remote interface.
  -  String _remote;
  -  // The ejb-link element is used in the ejb-ref element to specify
  -  // that an EJB reference is linked to an EJB in an encompassing
  -  // Java2 Enterprise Edition (J2EE) application package. The value of
  -  // the ejb-link element must be the ejb-name of an EJB in the J2EE
  -  // application package.
  -  String _ejbLink;
  -
  -  // I could do some verification after each of these atributes is
  -  // set....?
  -
  -  public void set_ejb_ref_name (String name)   {_ejbRefName =name;}
  -  public void set_ejb_ref_type (String type)   {_ejbRefType =type;} 
  -  public void set_home         (String home)   {_home       =home;}
  -  public void set_remote       (String remote) {_remote     =remote;} 
  -  public void set_ejb_link     (String name)   {_ejbLink    =name;}
  -
     public void
  -    set_ejb_ref(String dummy)
  -  {
  -    doBinding(_ejbRefName, _ejbLink);
  -  }
  -
  -  public String
  -    toString()
  +    put(String key, URL val)
     {
  -    return "<EJBRefHandler:"+
  -      "name="+_ejbRefName+","+
  -      "type="+_ejbRefType+","+
  -      "home="+_home+","+
  -      "remote="+_remote+
  -      "link="+_ejbLink+
  -      ">";
  +    _table.put(key, val);
     }
   }
  -
  + 
   class Jetty extends com.mortbay.Jetty.Server
   {
  +  JettyResolver _resolver=new JettyResolver();
  +  
     Jetty()
     {
       super();
  +    
  +    URL 
stdWeb=findResourceInJar("com.mortbay.HTTP.HttpServer","com/mortbay/Jetty/Servlet/web.dtd");
  +    _resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", stdWeb);
  +    
  +    URL 
jbossWeb=findResourceInJar("org.jboss.web.AbstractWebContainer","org/jboss/metadata/jboss-web.dtd");
  +    _resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb);
     }
   
     //----------------------------------------
  @@ -234,29 +165,56 @@
   
     Hashtable _deployed = new Hashtable();
   
  -  public void
  +  public WebApplication
       deploy(String path, String warUrl)
       throws DeploymentException
     {
  +    WebApplication wa=new WebApplication();
  +
       try
       {
  +      wa.setURL(new URL(warUrl));
  +
         // deploy the WebApp
         WebApplicationContext app=new WebApplicationContext(this, path+"/*");
  +      wa.setAppData(app);
   
         addContext(null, app);
   
         // Use the same ClassLoader as JBoss - this allows optimisation
         // of calls to EJBs...
         app.setClassLoader(Thread.currentThread().getContextClassLoader());
  +      wa.setClassLoader(Thread.currentThread().getContextClassLoader());
   
  -      // set up ENC stuff
  -      XmlParser parser=app.getXmlParser();
  -      parser.addContentHandler("ejb-ref", new EJBRefHandler());
  -
         app.initialize(warUrl+(warUrl.endsWith("/")?"":"/"),
                     getWebDefault(),
                     getUnpackWars());
         
  +      wa.setName(app.getDisplayName());
  +
  +      DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  +      DocumentBuilder parser=factory.newDocumentBuilder();
  +
  +      // locate and register $JETTY_HOME//etc/dtd/web.dtd
  +      //      parser.setErrorHandler();
  +      parser.setEntityResolver(_resolver);
  +      
  +      // MANDATORY - web.xml
  +      Resource web=app.getResource("/WEB-INF/web.xml");
  +      wa.setWebApp(parser.parse(web.getInputStream()).getDocumentElement());
  +      
  +      try
  +      {
  +     // OPTIONAL - jboss-web.xml
  +     Resource jbossWeb=app.getResource("/WEB-INF/jboss-web.xml");
  +     if (jbossWeb!=null)
  +       wa.setJbossWeb(parser.parse(jbossWeb.getInputStream()).getDocumentElement());
  +      }
  +      catch (FileNotFoundException e)
  +      {
  +     System.err.println("no jboss-web.xml found");
  +      }
  +      
         // finally - start the WebApp...
         app.start();
         
  @@ -271,6 +229,8 @@
         e.printStackTrace();
         throw new DeploymentException(e.getMessage());
       }
  +
  +    return wa;
     }
     
     public void
  @@ -301,5 +261,23 @@
       isDeployed(String warUrl)
     {
       return _deployed.containsKey(warUrl);
  +  }
  +
  +  static public URL
  +    findResourceInJar(String sibling, String name)
  +  {
  +    URL url=null;
  +    
  +    try
  +    {
  +      ClassLoader loader=Class.forName(sibling).getClassLoader();
  +      url=loader.getResource(name);
  +    }
  +    catch (Exception e)
  +    {
  +      System.err.println("Could not find resource: "+name);
  +    }
  +    
  +    return url;
     }
   }
  
  
  
  1.12      +32 -13    contrib/jetty/src/main/org/jboss/jetty/JettyService.java
  
  Index: JettyService.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyService.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JettyService.java 2001/05/09 22:45:59     1.11
  +++ JettyService.java 2001/05/18 22:01:38     1.12
  @@ -16,6 +16,8 @@
   
   import javax.management.*;
   
  +import org.jboss.web.AbstractWebContainer;
  +import org.jboss.web.WebApplication;
   import org.jboss.logging.Log;
   import org.jboss.logging.Logger;
   import org.jboss.util.ServiceMBeanSupport;
  @@ -33,7 +35,7 @@
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Julian Gosnell</a>
  - *   @version $Revision: 1.11 $
  + *   @version $Revision: 1.12 $
    */
   
   class JettyMBean extends HttpServerMBean
  @@ -79,8 +81,26 @@
       Logger.getLogger().fireNotification(type, _source, message);
     }
   }
  -  
  -public class JettyService extends ServiceMBeanSupport
  +
  +// NOTES
  +
  +// 1. it would be better if performUndeploy() passed us the appData,
  +// so we did not have to maintain our own warUrl:userData hashtable
  +
  +// 2. DOM is not the fastest way of parsing an XML file. Does Scott
  +// really need the DOM lying around after he has set up all the
  +// naming? could he make use of the fact that Greg has already done a
  +// pass over web.xml
  +
  +// 3. Can Greg provide me with a method for retrieving web.xml and
  +// jboss-web.xml InputStreams ?
  +
  +// 4. Looks like Greg may have to split up his start() method so that
  +// we can ensure that all naming and security services are started
  +// before the webapp itself. We need to get at the jboss-web.xml file
  +// and parse it before he fires up the webapp - or do we ??
  +
  +public class JettyService extends AbstractWebContainer
     implements JettyServiceMBean, MBeanRegistration
   {
     public static final String NAME = "Jetty";
  @@ -294,25 +314,25 @@
     // 'deploy' interface
     //----------------------------------------------------------------------------
   
  -  public void
  -    deploy(String path, String warUrl)
  +  public WebApplication
  +    performDeploy(String path, String warUrl)
       throws DeploymentException
     {
  -    _jetty.deploy(path, warUrl);
  +    return _jetty.deploy(path, warUrl);
     }
        
     public void
  -    undeploy(String warUrl)
  +    performUndeploy(String warUrl)
       throws DeploymentException
     {
       _jetty.undeploy(warUrl);
     }
     
  -  public boolean
  -    isDeployed(String warUrl)
  -  {
  -    return _jetty.isDeployed(warUrl);
  -  }
  +//   public boolean
  +//     isDeployed(String warUrl)
  +//   {
  +//     return _jetty.isDeployed(warUrl);
  +//   }
   
     //----------------------------------------------------------------------------
   
  @@ -398,5 +418,4 @@
       else
         return _jettyHome;
     }
  -
   }
  
  
  
  1.5       +5 -5      contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java
  
  Index: JettyServiceMBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JettyServiceMBean.java    2001/04/30 22:44:49     1.4
  +++ JettyServiceMBean.java    2001/05/18 22:01:38     1.5
  @@ -16,10 +16,10 @@
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    */
   public interface JettyServiceMBean
  -  extends org.jboss.util.ServiceMBean
  +  extends org.jboss.web.AbstractWebContainerMBean
   {
     
     // Constants -----------------------------------------------------
  @@ -27,9 +27,9 @@
     
     // Public --------------------------------------------------------
   
  -  public void deploy(String ctxPath, String warUrl) throws DeploymentException;
  -  public void undeploy(String warUrl) throws DeploymentException;
  -  public boolean isDeployed(String warUrl);
  +//   public void deploy(String ctxPath, String warUrl) throws DeploymentException;
  +//   public void undeploy(String warUrl) throws DeploymentException;
  +//   public boolean isDeployed(String warUrl);
   
     public void setConfiguration(String configUrl); // deprecated
     public void addConfiguration(String configUrl);
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to