tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup TldConfig.java
Date Thu, 12 Jun 2003 22:41:20 GMT
remm        2003/06/12 15:41:19

  Modified:    catalina/src/share/org/apache/catalina/startup
                        TldConfig.java
  Log:
  - Replace JAR URL code with regular JAR files (as the CL is forced to generate
    JAR URLs).
  - Jasper apparently causes JAR locking.
  - Struts is locking iteslf up. My theory is that it is caused by loading up a DTD
    for validation by the XML parser through a JAR URL without setting caches to false.
    I'll investigate more.
  
  Revision  Changes    Path
  1.11      +39 -63    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/TldConfig.java
  
  Index: TldConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/TldConfig.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TldConfig.java	24 Apr 2003 19:35:49 -0000	1.10
  +++ TldConfig.java	12 Jun 2003 22:41:19 -0000	1.11
  @@ -232,7 +232,7 @@
           }
           paths = globalJarPaths.iterator();
           while (paths.hasNext()) {
  -            tldScanJar((JarURLConnection) paths.next());
  +            tldScanJar((File) paths.next());
           }
   
           String list[] = getTldListeners();
  @@ -294,11 +294,11 @@
   
   	paths = globalJarPaths.iterator();
   	while (paths.hasNext()) {
  -	    JarURLConnection conn = (JarURLConnection) paths.next();
  -	    long lastM = conn.getLastModified();
  +	    File jarFile = (File) paths.next();
  +	    long lastM = jarFile.lastModified();
   	    if (lastM > lastModified) lastModified = lastM;
   	    if (log.isDebugEnabled()) {
  -		log.debug("Last modified " + conn.getJarFileURL().toString()
  +		log.debug("Last modified " + jarFile.getAbsolutePath()
   			  + " " + lastM);
   	    }
   	}
  @@ -438,33 +438,35 @@
           }
   
   	URL url = context.getServletContext().getResource(resourcePath);
  -	if (url == null) {
  +        if (url == null) {
   	    throw new IllegalArgumentException
   		(sm.getString("contextConfig.tldResourcePath",
   			      resourcePath));
   	}
  -	url = new URL("jar:" + url.toString() + "!/");
  -	JarURLConnection conn = (JarURLConnection) url.openConnection();
  -	conn.setUseCaches(false);
  -	tldScanJar(conn);
  +
  +        File file = new File(url.getFile());
  +        file = file.getCanonicalFile();
  +        tldScanJar(file);
  +
       }
   
  -    /*
  +
  +    /**
        * Scans all TLD entries in the given JAR for application listeners.
        *
        * @param conn URLConnection to the JAR file whose TLD entries are
        * scanned for application listeners
        */
  -    private void tldScanJar(JarURLConnection conn) throws Exception {
  +    private void tldScanJar(File file) throws Exception {
   
           JarFile jarFile = null;
           String name = null;
           InputStream inputStream = null;
   
  -	String jarPath = conn.getJarFileURL().toString();
  +	String jarPath = file.getAbsolutePath();
   
   	try {
  -	    jarFile = conn.getJarFile();
  +	    jarFile = new JarFile(file);
               Enumeration entries = jarFile.entries();
               while (entries.hasMoreElements()) {
                   JarEntry entry = (JarEntry) entries.nextElement();
  @@ -512,6 +514,7 @@
           }
       }
   
  +
       /**
        * Scan the TLD contents in the specified input stream, and register
        * any application event listeners found there.  <b>NOTE</b> - It is
  @@ -692,7 +695,8 @@
           }
       }
   
  -    /*
  +
  +    /**
        * Returns the paths to all JAR files accessible to all parent
        * classloaders of the web application class loader.
        *
  @@ -703,60 +707,32 @@
        * <CATALINA_HOME>/common/lib).
        *
        * @return Set of paths to all JAR files accessible to all parent class
  -     * loaders of the web application class loader
  +     *         loaders of the web application class loader
        */
       private Set getGlobalJarPaths() throws IOException {
   
           Set globalJarPaths = new HashSet();
   
  -	ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -	while (loader != null) {
  -	    if (loader instanceof URLClassLoader) {
  -		URL[] urls = ((URLClassLoader) loader).getURLs();
  -		for (int i=0; i<urls.length; i++) {
  -		    JarURLConnection jarConn = null;
  -		    URLConnection conn = urls[i].openConnection();
  -		    if (conn instanceof JarURLConnection) {
  -			jarConn = (JarURLConnection) conn;
  -		    } else {
  -			String urlStr = urls[i].toString();
  -			if (urlStr.startsWith("file:")
  -			        && urlStr.endsWith(".jar")) {
  -			    URL jarURL = new URL("jar:" + urlStr + "!/");
  -			    jarConn = (JarURLConnection) jarURL.openConnection();
  -			    try {
  -				/*
  -				 * Call getJarFile() to see if JAR file exists
  -				 * (throws exception in case it doesn't)
  -				 */
  -				jarConn.getJarFile();
  -				/*
  -				 * JAR file exists.
  -				 * Need to create new JarURLConnection due to
  -				 * bug 4756443. If it were not for this bug,
  -				 * the sequence of calls in this try block
  -				 * would be as follows:
  -				 *   jarConn.setUseCaches(false);
  -				 *   jarConn.getJarFile();
  -				 *   globalJarPaths.add(jarConn);
  -				 */
  -				jarConn = (JarURLConnection)
  -				    jarURL.openConnection();
  -				jarConn.setUseCaches(false);
  -				globalJarPaths.add(jarConn);
  -			    } catch (Exception e) {
  -				/*
  -				 * Ignore any JAR files that may have been
  -				 * specified on the class path but don't exist
  -				 */
  -			    }
  -			}
  -		    }
  -		}
  -	    }
  -	    loader = loader.getParent();
  -	}
  +        ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +        while (loader != null) {
  +            if (loader instanceof URLClassLoader) {
  +                URL[] urls = ((URLClassLoader) loader).getURLs();
  +                for (int i=0; i<urls.length; i++) {
  +                    // Expect file URLs
  +                    // This is definitely not as clean as using JAR URLs either
  +                    // over file or the custom jndi handler, but a lot less
  +                    // buggy overall
  +                    File file = new File(urls[i].getFile());
  +                    file = file.getCanonicalFile();
  +                    if ((file.exists()) 
  +                        && (file.getAbsolutePath().endsWith(".jar"))) {
  +                        globalJarPaths.add(file);
  +                    }
  +                }
  +            }
  +            loader = loader.getParent();
  +        }
   
  -	return globalJarPaths;
  +        return globalJarPaths;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message