remm        01/01/18 21:58:24

  Modified:    catalina/src/share/org/apache/catalina/loader
                        StandardClassLoader.java StandardLoader.java
  Log:
  - The loader will attempt to copy the JARs files contained in the
    /WEB-INF/lib path of the JNDI context to the work directory, and load them
    from there. If the work directory is not present, then the loader will fall back
    to direct filesystem access, which may or may not succeed, depending on the
    type of JNDI context implementation used.
  
  Revision  Changes    Path
  1.7       +27 -13    
jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardClassLoader.java
  
  Index: StandardClassLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardClassLoader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StandardClassLoader.java  2001/01/13 05:27:54     1.6
  +++ StandardClassLoader.java  2001/01/19 05:58:24     1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardClassLoader.java,v
 1.6 2001/01/13 05:27:54 remm Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/01/13 05:27:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardClassLoader.java,v
 1.7 2001/01/19 05:58:24 remm Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/01/19 05:58:24 $
    *
    * ====================================================================
    *
  @@ -105,7 +105,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.6 $ $Date: 2001/01/13 05:27:54 $
  + * @version $Revision: 1.7 $ $Date: 2001/01/19 05:58:24 $
    */
   
   public class StandardClassLoader
  @@ -600,14 +600,27 @@
   
           // Check for modifications to any of these classes
           for (int i = 0; i < entries.length; i++) {
  -            if (!(entries[i].origin instanceof File))
  -                continue;
  -            File origin = (File) entries[i].origin;
  -            if (entries[i].lastModified != origin.lastModified()) {
  -                if (debug >= 2)
  -                    log("  Class '" + entries[i].loadedClass.getName() +
  -                        "' was modified");
  -                return (true);
  +            if (entries[i].origin instanceof File) {
  +                File origin = (File) entries[i].origin;
  +                if (entries[i].lastModified != origin.lastModified()) {
  +                    if (debug >= 2)
  +                        log("  Class '" + entries[i].loadedClass.getName() +
  +                            "' was modified");
  +                    return (true);
  +                }
  +            } else if (entries[i].origin instanceof URL) {
  +                try {
  +                    URL url = (URL) entries[i].origin;
  +                    URLConnection urlConn = url.openConnection();
  +                    if (entries[i].lastModified != urlConn.getLastModified()) {
  +                        if (debug >= 2)
  +                            log("  Class '" 
  +                                + entries[i].loadedClass.getName() 
  +                                + "' was modified");
  +                        return (true);
  +                    }
  +                } catch (IOException e) {
  +                }
               }
           }
   
  @@ -1144,8 +1157,9 @@
                           Extension.getRequired(manifest).iterator();
                       while (extensions.hasNext())
                           required.add(extensions.next());
  -                    jarFile.close();
                   }
  +                if (jarFile != null)
  +                    jarFile.close();
               } catch (Throwable t) {
                   t.printStackTrace();
                   throw new IllegalArgumentException
  
  
  
  1.17      +96 -59    
jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardLoader.java
  
  Index: StandardLoader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardLoader.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StandardLoader.java       2001/01/14 19:53:47     1.16
  +++ StandardLoader.java       2001/01/19 05:58:24     1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardLoader.java,v
 1.16 2001/01/14 19:53:47 remm Exp $
  - * $Revision: 1.16 $
  - * $Date: 2001/01/14 19:53:47 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/loader/StandardLoader.java,v
 1.17 2001/01/19 05:58:24 remm Exp $
  + * $Revision: 1.17 $
  + * $Date: 2001/01/19 05:58:24 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,9 @@
   import java.beans.PropertyChangeSupport;
   import java.io.File;
   import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.FileOutputStream;
  +import java.io.OutputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.net.URLClassLoader;
  @@ -107,7 +110,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.16 $ $Date: 2001/01/14 19:53:47 $
  + * @version $Revision: 1.17 $ $Date: 2001/01/19 05:58:24 $
    */
   
   public final class StandardLoader
  @@ -873,70 +876,104 @@
               addRepository(classesURLString + "/");
           }
           
  -     // Add the WEB-INF/lib/*.jar files
  -        // FIXME - This still requires disk directory!  Scan JARs if present
  -        File libFile = new File(((Context) container).getDocBase(), 
  -                                "/WEB-INF/lib");
  -        if (libFile.exists() && libFile.canRead() &&
  -            libFile.isDirectory()) {
  -            String filenames[] = libFile.list();
  -            for (int i = 0; i < filenames.length; i++) {
  -                if (!filenames[i].endsWith(".jar"))
  -                    continue;
  -                File jarFile = new File(libFile, filenames[i]);
  +        // Loading the work directory
  +        File workDir = 
  +            (File) servletContext.getAttribute(Globals.WORK_DIR_ATTR);
  +
  +        if (workDir != null) {
  +
  +            DirContext resources = container.getResources();
  +            String libName = "/WEB-INF/lib";
  +            DirContext libDir = null;
  +            // Looking up directory /WEB-INF/lib in the context
  +            try {
  +                Object object = resources.lookup(libName);
  +                if (object instanceof DirContext)
  +                    libDir = (DirContext) object;
  +            } catch(NamingException e) {
  +                // Silent catch: it's valid that no /WEB-INF/lib directory 
  +                //exists
  +            }
  +
  +            // Add the WEB-INF/lib/*.jar files
  +            if (libDir != null) {
  +                // Enumerate children
                   try {
  -                    if (debug > 0)
  -                        log(" Adding '" + "file: " +
  -                            jarFile.getCanonicalPath() + "'");
  -                    addRepository("file:" + jarFile.getCanonicalPath());
  -                } catch (IOException e) {
  -                    log(jarFile.getAbsolutePath(), e);
  +                    NamingEnumeration enum = resources.list(libName);
  +                    while (enum.hasMoreElements()) {
  +                        NameClassPair ncPair = 
  +                            (NameClassPair) enum.nextElement();
  +                        String filename = ncPair.getName();
  +                        if (!filename.endsWith(".jar"))
  +                            continue;
  +                        try {
  +                            URL fileURL = servletContext.getResource
  +                                (libName + "/" + filename);
  +                            log(" Adding '" + "file: " +
  +                                libName + "/" + filename + "'");
  +                            // Copying the file to the work dir
  +                            File dest = new File(workDir, filename);
  +                            if (copyJAR(fileURL.openStream(), 
  +                                        new FileOutputStream(dest)))
  +                                addRepository(dest.toURL().toString());
  +                        } catch (MalformedURLException e) {
  +                        } catch (IOException e) {
  +                        }
  +                    }
  +                } catch(NamingException e) {
                   }
               }
  -        }
  -        
  -        // FIXME: The code below is the elegant version of the ten lines of 
  -        // code above. The problem is that it doesn't work due to some 
  -        // classloading issues (the URL classloader doesn't seem to like my
  -        // URL objects when they point to JAR files, although loading of
  -        // individual classes work fine).
  -        
  -/*
  -        DirContext resources = container.getResources();
  -        String libName = "/WEB-INF/lib";
  -        DirContext libDir = null;
  -        // Looking up directory /WEB-INF/lib in the context
  -        try {
  -            Object object = resources.lookup(libName);
  -            if (object instanceof DirContext)
  -                libDir = (DirContext) object;
  -        } catch(NamingException e) {
  -            // Silent catch: it's valid that no /WEB-INF/lib directory exists
  -        }
   
  -     // Add the WEB-INF/lib/*.jar files
  -        if (libDir != null) {
  -            // Enumerate children
  -            try {
  -                NamingEnumeration enum = resources.list(libName);
  -                while (enum.hasMoreElements()) {
  -                    NameClassPair ncPair = (NameClassPair) enum.nextElement();
  -                    String filename = ncPair.getName();
  -                    if (!filename.endsWith(".jar"))
  -                     continue;
  +        } else {
  +
  +            // Add the WEB-INF/lib/*.jar files
  +            // This requires disk directory!  Scan JARs if present
  +
  +            File libFile = new File(((Context) container).getDocBase(), 
  +                                    "/WEB-INF/lib");
  +            if (libFile.exists() && libFile.canRead() &&
  +                libFile.isDirectory()) {
  +                String filenames[] = libFile.list();
  +                for (int i = 0; i < filenames.length; i++) {
  +                    if (!filenames[i].endsWith(".jar"))
  +                        continue;
  +                    File jarFile = new File(libFile, filenames[i]);
                       try {
  -                        URL fileURL = servletContext.getResource
  -                            (libName + "/" + filename);
  -                        log(" Adding '" + "file: " +
  -                            libName + "/" + filename + "'");
  -                        addRepository(fileURL.toString());
  -                    } catch (MalformedURLException e) {
  +                        if (debug > 0)
  +                            log(" Adding '" + "file: " +
  +                                jarFile.getCanonicalPath() + "'");
  +                        addRepository("file:" + jarFile.getCanonicalPath());
  +                    } catch (IOException e) {
  +                        log(jarFile.getAbsolutePath(), e);
                       }
                   }
  -            } catch(NamingException e) {
               }
  +
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Copy a JAR file to the specified temp directory.
  +     */
  +    private boolean copyJAR(InputStream is, OutputStream os) {
  +
  +        try {
  +            byte[] buf = new byte[4096];
  +            while (true) {
  +                int len = is.read(buf);
  +                if (len < 0)
  +                    break;
  +                os.write(buf, 0, len);
  +            }
  +            is.close();
  +            os.close();
  +        } catch (IOException e) {
  +            return false;
           }
  -*/
  +
  +        return true;
   
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to