gregw       2004/02/04 17:37:56

  Modified:    modules/jetty/src/java/org/apache/geronimo/jetty
                        JettyWebApplicationContext.java
               modules/jetty/src/java/org/apache/geronimo/jetty/deployment
                        AbstractModule.java JettyModule.java
                        UnpackedModule.java WebAppDConfigBean.java
               modules/jetty/src/test/org/apache/geronimo/jetty/deployment
                        WARConfigurationFactoryTest.java
               modules/jetty/src/test-resources/deployables/war1/WEB-INF
                        geronimo-web.xml
  Log:
  Added GBean attribute contextPriorityClassLoader.   If set true then the
  servlet spec recommendation is used for classloading.
  
  If set to false ( the default ) then it is not.   We should be able to
  directly use the geronimo loader as the context loader, but currently
  it does not appear to find the WEB-INF/lib and WEB-INF/classes stuff, so
  we are still making a jetty loader.
  
  Also added the attribute to the DConfigBean, but currently it does not
  appear that this is actualy being used by anything other than the tests?
  
  Revision  Changes    Path
  1.8       +48 -1     
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java
  
  Index: JettyWebApplicationContext.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JettyWebApplicationContext.java   31 Jan 2004 19:27:17 -0000      1.7
  +++ JettyWebApplicationContext.java   5 Feb 2004 01:37:56 -0000       1.8
  @@ -56,6 +56,7 @@
   package org.apache.geronimo.jetty;
   
   import java.io.IOException;
  +import java.net.MalformedURLException;
   import java.net.URI;
   import java.net.URL;
   import java.util.Arrays;
  @@ -70,6 +71,8 @@
   import javax.transaction.Transaction;
   import javax.transaction.TransactionManager;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import 
org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
   import 
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
   import 
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  @@ -97,6 +100,9 @@
    * @version $Revision$ $Date$
    */
   public class JettyWebApplicationContext extends WebApplicationContext 
implements GBean {
  +
  +    private static Log log = 
LogFactory.getLog(JettyWebApplicationContext.class);
  +    
       private final ConfigurationParent config;
       private final URI uri;
       private final JettyContainer container;
  @@ -111,6 +117,7 @@
       // @todo get these from DD
       private final Set unshareableResources = Collections.EMPTY_SET;
   
  +    private boolean contextPriorityClassLoader=false;
   
       public JettyWebApplicationContext(
               ConfigurationParent config,
  @@ -130,6 +137,43 @@
           this.associator = associator;
       }
   
  +    
  +    /** getContextPriorityClassLoader.
  +     * @return True if this context should give web application class in 
preference over the containers 
  +      * classes, as per the servlet specification recommendations.
  +     */
  +    public boolean getContextPriorityClassLoader() {
  +        return contextPriorityClassLoader;
  +    }
  +
  +    /** setContextPriorityClassLoader.
  +     * @param b True if this context should give web application class in 
preference over the containers 
  +     * classes, as per the servlet specification recommendations.
  +     */
  +    public void setContextPriorityClassLoader(boolean b) {
  +        contextPriorityClassLoader= b;
  +    }
  +    
  +    /**
  +     * init the classloader. Uses the value of contextPriorityClassLoader to 
  +     * determine if the context needs to create its own classloader.
  +     */
  +    protected void initClassLoader(boolean forceContextLoader) 
  +        throws MalformedURLException, IOException
  +    {
  +        setClassLoaderJava2Compliant(!contextPriorityClassLoader);
  +        if (!contextPriorityClassLoader)
  +        {
  +            // TODO - once geronimo is correctly setting up the classpath, 
this should be uncommented.
  +            // At the moment, the g classloader does not appear to know 
about the WEB-INF classes and lib.
  +            // 
setClassLoader(Thread.currentThread().getContextClassLoader());
  +        }
  +        super.initClassLoader(forceContextLoader);
  +        
  +        if (log.isDebugEnabled())
  +            log.debug("classloader for "+getContextPath()+": 
"+getClassLoader());
  +    }
  +    
       public void handle(String pathInContext,
                          String pathParams,
                          HttpRequest httpRequest,
  @@ -232,9 +276,11 @@
       public static final GBeanInfo GBEAN_INFO;
   
       static {
  +
           GBeanInfoFactory infoFactory = new GBeanInfoFactory("Jetty 
WebApplication Context", JettyWebApplicationContext.class.getName());
           infoFactory.addAttribute(new GAttributeInfo("URI", true));
           infoFactory.addAttribute(new GAttributeInfo("ContextPath", true));
  +        infoFactory.addAttribute(new 
GAttributeInfo("ContextPriorityClassLoader", true));
           infoFactory.addAttribute(new GAttributeInfo("ComponentContext", 
true));
           infoFactory.addAttribute(new GAttributeInfo("PolicyContextID", 
true));
           infoFactory.addReference(new GReferenceInfo("Configuration", 
ConfigurationParent.class.getName()));
  @@ -251,4 +297,5 @@
       public static GBeanInfo getGBeanInfo() {
           return GBEAN_INFO;
       }
  +
   }
  
  
  
  1.4       +6 -3      
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java
  
  Index: AbstractModule.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/AbstractModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractModule.java       26 Jan 2004 05:55:27 -0000      1.3
  +++ AbstractModule.java       5 Feb 2004 01:37:56 -0000       1.4
  @@ -77,7 +77,8 @@
       protected final URI configID;
       protected URI uri;
       protected String contextPath;
  -
  +    protected boolean contextPriorityClassLoader;
  +    
       public AbstractModule(URI configID) {
           this.configID = configID;
       }
  @@ -101,6 +102,7 @@
               GBeanMBean app = new 
GBeanMBean(JettyWebApplicationContext.GBEAN_INFO);
               app.setAttribute("URI", uri);
               app.setAttribute("ContextPath", contextPath);
  +            app.setAttribute("ContextPriorityClassLoader", new 
Boolean(contextPriorityClassLoader));     
               app.setAttribute("ComponentContext", null);
               app.setAttribute("PolicyContextID", null);
               app.setReferencePatterns("Configuration", 
Collections.singleton(Kernel.getConfigObjectName(configID)));
  @@ -108,7 +110,8 @@
               app.setReferencePatterns("TransactionManager", 
Collections.EMPTY_SET);
               app.setReferencePatterns("TrackedConnectionAssociator", 
Collections.EMPTY_SET);
               callback.addGBean(name, app);
  -        } catch (Exception e) {
  +            
  +        } catch (Throwable e) {
               throw new DeploymentException("Unable to build GBean for web 
application", e);
           }
       }
  
  
  
  1.7       +35 -19    
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java
  
  Index: JettyModule.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModule.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JettyModule.java  27 Jan 2004 06:05:43 -0000      1.6
  +++ JettyModule.java  5 Feb 2004 01:37:56 -0000       1.7
  @@ -82,15 +82,19 @@
       private URI classes;
       private URI lib;
   
  -    public JettyModule(URI configID, InputStream moduleArchive, Document 
deploymentPlan) throws DeploymentException {
  +    public JettyModule(URI configID, InputStream moduleArchive, Document 
deploymentPlan) throws DeploymentException
  +    {
           super(configID);
  -        moduleDirectory = null;
  -        this.zipArchive = new ZipInputStream(moduleArchive);
  -        closeStream = false;
  -        contextPath = 
XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", 
null, null);
  -        if (contextPath == null) {
  +        moduleDirectory= null;
  +        this.zipArchive= new ZipInputStream(moduleArchive);
  +        closeStream= false;
  +
  +        // TODO - why does this not use the WebAppDConfigBean ??
  +        contextPath= 
XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", 
null, null);
  +        if (contextPath == null)
               throw new DeploymentException("No context root specified");
  -        }
  +        String 
t=XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), 
"context-priority-classloader", null, null);
  +        contextPriorityClassLoader= t != null && t.length() > 0 && 
t.toLowerCase().charAt(0) == 't';
       }
   
       public JettyModule(URI configID, File archiveFile, Document 
deploymentPlan) throws DeploymentException {
  @@ -117,6 +121,10 @@
           if (!contextPath.startsWith("/")) {
               contextPath = "/" + contextPath;
           }
  +        
  +        // TODO - why does this not use the WebAppDConfigBean ??
  +        String 
t=XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), 
"context-priority-classloader", null, null);
  +        contextPriorityClassLoader= t != null && t.length() > 0 && 
t.toLowerCase().charAt(0) == 't';
       }
   
       public void init() throws DeploymentException {
  @@ -132,29 +140,37 @@
               // unpack archive into Configuration
               try {
                   ZipEntry entry;
  -                boolean addedClasses = false;
  -                while ((entry = zipArchive.getNextEntry()) != null) {
  -                    String name = entry.getName();
  +                boolean addedClasses= false;
  +                while ((entry= zipArchive.getNextEntry()) != null) {
  +                    String name= entry.getName();
                       if (name.endsWith("/")) {
                           continue;
                       }
                       callback.addFile(uri.resolve(name), zipArchive);
  -                    if (!addedClasses && 
name.startsWith("WEB-INF/classes/")) {
  -                        callback.addToClasspath(classes);
  -                    } else if (name.startsWith("WEB-INF/lib/")) {
  -                        if (name.indexOf('/', 12) == -1 && 
(name.endsWith(".jar") || name.endsWith(".zip"))) {
  -                            callback.addToClasspath(uri.resolve(name));
  +
  +                    // If we do not give the context priority over 
classloading, then we add the standard locations to our classpath.
  +                    if (!contextPriorityClassLoader) {
  +                        if (!addedClasses && 
name.startsWith("WEB-INF/classes/")) {
  +                            callback.addToClasspath(classes);
  +                        }
  +                        else if (name.startsWith("WEB-INF/lib/")) {
  +                            if (name.indexOf('/', 12) == -1 && 
(name.endsWith(".jar") || name.endsWith(".zip"))) {
  +                                callback.addToClasspath(uri.resolve(name));
  +                            }
                           }
                       }
                   }
  -            } catch (IOException e) {
  +            }
  +            catch (IOException e) {
                   throw new DeploymentException("Unable to unpack WAR 
content", e);
               }
  -        } else {
  +        }
  +        else {
               // copy directory into Configuration
               try {
                   copyDir(callback, uri, moduleDirectory);
  -            } catch (IOException e) {
  +            }
  +            catch (IOException e) {
                   throw new DeploymentException("Unable to copy archive 
directory", e);
               }
           }
  
  
  
  1.3       +5 -3      
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/UnpackedModule.java
  
  Index: UnpackedModule.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/UnpackedModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnpackedModule.java       26 Jan 2004 05:55:27 -0000      1.2
  +++ UnpackedModule.java       5 Feb 2004 01:37:56 -0000       1.3
  @@ -67,6 +67,7 @@
    * @version $Revision$ $Date$
    */
   public class UnpackedModule extends AbstractModule {
  +   
       public UnpackedModule(URI configID, File archive, Document 
deploymentPlan) {
           super(configID);
           this.uri = archive.toURI();
  @@ -75,6 +76,7 @@
               contextPath = contextPath.substring(0, contextPath.length() - 4);
           }
           contextPath = 
XMLUtil.getChildContent(deploymentPlan.getDocumentElement(), "context-root", 
contextPath, contextPath);
  -    }
  -
  +    }    
  +    
  +    // TODO - generate classpath?
   }
  
  
  
  1.4       +27 -1     
incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WebAppDConfigBean.java
  
  Index: WebAppDConfigBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/WebAppDConfigBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebAppDConfigBean.java    23 Jan 2004 19:58:17 -0000      1.3
  +++ WebAppDConfigBean.java    5 Feb 2004 01:37:56 -0000       1.4
  @@ -74,6 +74,7 @@
    */
   public class WebAppDConfigBean extends DConfigBeanSupport {
       private String contextRoot;
  +    private boolean contextPriorityClassLoader;
   
       private final ENCHelper encHelper;
   
  @@ -90,6 +91,28 @@
           pcs.firePropertyChange("contextRoot", this.contextRoot, contextRoot);
           this.contextRoot = contextRoot;
       }
  +    
  +         
  +         /* 
------------------------------------------------------------------------------- 
*/
  +         /** getContextPriorityClassLoader.
  +          * @return True if this context should give web application class 
in preference over the containers 
  +          * classes, as per the servlet specification recommendations.
  +          */
  +         public boolean getContextPriorityClassLoader(){
  +             return contextPriorityClassLoader;
  +         }
  +     
  +         /* 
------------------------------------------------------------------------------- 
*/
  +         /** setContextPriorityClassLoader.
  +          * @param contextPriority True if this context should give web 
application class in preference over the containers 
  +          * classes, as per the servlet specification recommendations.
  +          */
  +         public void setContextPriorityClassLoader(boolean p){
  +             pcs.firePropertyChange("contextPriorityClassLoader", 
this.contextPriorityClassLoader, p);
  +               this.contextPriorityClassLoader = p;
  +         }
  +
  +
   
       public DConfigBean getDConfigBean(DDBean ddBean) throws 
ConfigurationException {
           return encHelper.getDConfigBean(ddBean);
  @@ -108,6 +131,9 @@
               writer.print("<context-root>");
               writer.print(contextRoot);
               writer.println("</context-root>");
  +            writer.print("<context-priority-classloader>");
  +            writer.print(contextPriorityClassLoader);
  +            writer.println("</context-priority-classloader>");
           }
           encHelper.toXML(writer);
       }
  
  
  
  1.6       +7 -1      
incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/WARConfigurationFactoryTest.java
  
  Index: WARConfigurationFactoryTest.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/test/org/apache/geronimo/jetty/deployment/WARConfigurationFactoryTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WARConfigurationFactoryTest.java  4 Feb 2004 05:54:08 -0000       1.5
  +++ WARConfigurationFactoryTest.java  5 Feb 2004 01:37:56 -0000       1.6
  @@ -96,6 +96,7 @@
           DConfigBeanRoot configRoot = 
config.getDConfigBeanRoot(deployable.getDDBeanRoot());
           WebAppDConfigBean contextBean = (WebAppDConfigBean) 
configRoot.getDConfigBean(deployable.getChildBean("/web-app")[0]);
           contextBean.setContextRoot("/test");
  +        contextBean.setContextPriorityClassLoader(false);
   
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           config.save(baos);
  @@ -104,6 +105,9 @@
           assertEquals("web-app", root.getNodeName());
           Element contextRoot = XMLUtil.getChild(root, "context-root");
           assertEquals("/test", XMLUtil.getContent(contextRoot));
  +        
  +        Element contextPriority = XMLUtil.getChild(root, 
"context-priority-classloader");
  +        assertEquals("false", XMLUtil.getContent(contextPriority));
       }
   
       public void testConfigSaveRestore() throws Exception {
  @@ -112,6 +116,7 @@
           DConfigBeanRoot configRoot = 
config.getDConfigBeanRoot(deployable.getDDBeanRoot());
           WebAppDConfigBean contextBean = (WebAppDConfigBean) 
configRoot.getDConfigBean(deployable.getChildBean("/web-app")[0]);
           contextBean.setContextRoot("/test");
  +        contextBean.setContextPriorityClassLoader(true);
   
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           config.save(baos);
  @@ -123,6 +128,7 @@
           assertNull(contextBean.getContextRoot());
           config.restore(new ByteArrayInputStream(baos.toByteArray()));
           assertEquals("/test", contextBean.getContextRoot());
  +        contextBean.setContextPriorityClassLoader(true);
       }
   
       protected void setUp() throws Exception {
  
  
  
  1.2       +1 -0      
incubator-geronimo/modules/jetty/src/test-resources/deployables/war1/WEB-INF/geronimo-web.xml
  
  Index: geronimo-web.xml
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/jetty/src/test-resources/deployables/war1/WEB-INF/geronimo-web.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- geronimo-web.xml  24 Jan 2004 21:07:45 -0000      1.1
  +++ geronimo-web.xml  5 Feb 2004 01:37:56 -0000       1.2
  @@ -1,3 +1,4 @@
   <web-app>
       <context-root>/test</context-root>
  +    <context-priority-classloader>false</context-priority-classloader>
   </web-app>
  
  
  

Reply via email to