craigmcc    02/03/04 17:53:12

  Modified:    catalina/src/share/org/apache/catalina/startup
                        ContextConfig.java
  Log:
  Fix a race condition that could cause problems if two contexts are being
  started simultaneously.  The start() method was already synchronized, but
  this only helps you deal with two attempts to start the *same* app at the
  same time.  The underlying Digester instance would still be incorrectly
  shared.
  
  The symptom was parsing failures on one or both web.xml files -- this would
  happen rarely during a normal startup when you have lots of virtual
  hosts, but more often when you hammer on the manager webapp deploying and
  undeploying applications.
  
  Revision  Changes    Path
  1.59      +129 -134  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java
  
  Index: ContextConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- ContextConfig.java        20 Feb 2002 03:18:19 -0000      1.58
  +++ ContextConfig.java        5 Mar 2002 01:53:11 -0000       1.59
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
 1.58 2002/02/20 03:18:19 remm Exp $
  - * $Revision: 1.58 $
  - * $Date: 2002/02/20 03:18:19 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
 1.59 2002/03/05 01:53:11 craigmcc Exp $
  + * $Revision: 1.59 $
  + * $Date: 2002/03/05 01:53:11 $
    *
    * ====================================================================
    *
  @@ -127,7 +127,7 @@
    * of that Context, and the associated defined servlets.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.58 $ $Date: 2002/02/20 03:18:19 $
  + * @version $Revision: 1.59 $ $Date: 2002/03/05 01:53:11 $
    */
   
   public final class ContextConfig
  @@ -174,14 +174,14 @@
        * The <code>Digester</code> we will use to process tag library
        * descriptor files.
        */
  -    private static Digester tldDigester = null;
  +    private static Digester tldDigester = createTldDigester();
   
   
       /**
        * The <code>Digester</code> we will use to process web application
        * deployment descriptor files.
        */
  -    private static Digester webDigester = null;
  +    private static Digester webDigester = createWebDigester();
   
   
       // ------------------------------------------------------------- Properties
  @@ -261,29 +261,30 @@
           }
   
           // Process the application web.xml file
  -        try {
  -            Digester digester = createWebDigester();
  -            digester.setDebug(getDebug());
  -            synchronized (digester) {
  -                if (context instanceof StandardContext)
  -                    ((StandardContext) context).setReplaceWelcomeFiles(true);
  -                digester.push(context);
  -                digester.parse(stream);
  -            }
  -        } catch (SAXParseException e) {
  -            log(sm.getString("contextConfig.applicationParse"), e);
  -            log(sm.getString("contextConfig.applicationPosition",
  -                             "" + e.getLineNumber(),
  -                             "" + e.getColumnNumber()));
  -            ok = false;
  -        } catch (Exception e) {
  -            log(sm.getString("contextConfig.applicationParse"), e);
  -            ok = false;
  -        } finally {
  +        synchronized (webDigester) {
               try {
  -                stream.close();
  -            } catch (IOException e) {
  -                log(sm.getString("contextConfig.applicationClose"), e);
  +                webDigester.setDebug(getDebug());
  +                if (context instanceof StandardContext) {
  +                    ((StandardContext) context).setReplaceWelcomeFiles(true);
  +                }
  +                webDigester.clear();
  +                webDigester.push(context);
  +                webDigester.parse(stream);
  +            } catch (SAXParseException e) {
  +                log(sm.getString("contextConfig.applicationParse"), e);
  +                log(sm.getString("contextConfig.applicationPosition",
  +                                 "" + e.getLineNumber(),
  +                                 "" + e.getColumnNumber()));
  +                ok = false;
  +            } catch (Exception e) {
  +                log(sm.getString("contextConfig.applicationParse"), e);
  +                ok = false;
  +            } finally {
  +                try {
  +                    stream.close();
  +                } catch (IOException e) {
  +                    log(sm.getString("contextConfig.applicationClose"), e);
  +                }
               }
           }
   
  @@ -431,22 +432,18 @@
        * library descriptor, looking for additional listener classes to be
        * registered.
        */
  -    private synchronized Digester createTldDigester() {
  +    private static Digester createTldDigester() {
   
           URL url = null;
  -        if (tldDigester == null) {
  -            tldDigester = new Digester();
  -            if (debug > 0)
  -                tldDigester.setDebug(3);
  -            tldDigester.setValidating(true);
  -            url = this.getClass().getResource(Constants.TldDtdResourcePath_11);
  -            tldDigester.register(Constants.TldDtdPublicId_11,
  -                              url.toString());
  -            url = this.getClass().getResource(Constants.TldDtdResourcePath_12);
  -            tldDigester.register(Constants.TldDtdPublicId_12,
  -                              url.toString());
  -            tldDigester.addRuleSet(new TldRuleSet());
  -        }
  +        Digester tldDigester = new Digester();
  +        tldDigester.setValidating(true);
  +        url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_11);
  +        tldDigester.register(Constants.TldDtdPublicId_11,
  +                             url.toString());
  +        url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_12);
  +        tldDigester.register(Constants.TldDtdPublicId_12,
  +                             url.toString());
  +        tldDigester.addRuleSet(new TldRuleSet());
           return (tldDigester);
   
       }
  @@ -456,22 +453,18 @@
        * Create (if necessary) and return a Digester configured to process the
        * web application deployment descriptor (web.xml).
        */
  -    private synchronized Digester createWebDigester() {
  +    private static Digester createWebDigester() {
   
           URL url = null;
  -        if (webDigester == null) {
  -            webDigester = new Digester();
  -            if (debug > 0)
  -                webDigester.setDebug(3);
  -            webDigester.setValidating(true);
  -            url = this.getClass().getResource(Constants.WebDtdResourcePath_22);
  -            webDigester.register(Constants.WebDtdPublicId_22,
  -                              url.toString());
  -            url = this.getClass().getResource(Constants.WebDtdResourcePath_23);
  -            webDigester.register(Constants.WebDtdPublicId_23,
  -                              url.toString());
  -            webDigester.addRuleSet(new WebRuleSet());
  -        }
  +        Digester webDigester = new Digester();
  +        webDigester.setValidating(true);
  +        url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_22);
  +        webDigester.register(Constants.WebDtdPublicId_22,
  +                             url.toString());
  +        url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_23);
  +        webDigester.register(Constants.WebDtdPublicId_23,
  +                             url.toString());
  +        webDigester.addRuleSet(new WebRuleSet());
           return (webDigester);
   
       }
  @@ -499,29 +492,29 @@
           }
   
           // Process the default web.xml file
  -        try {
  -            Digester digester = createWebDigester();
  -            digester.setDebug(getDebug());
  -            synchronized (digester) {
  +        synchronized (webDigester) {
  +            try {
  +                webDigester.setDebug(getDebug());
                   if (context instanceof StandardContext)
                       ((StandardContext) context).setReplaceWelcomeFiles(true);
  -                digester.push(context);
  -                digester.parse(stream);
  -            }
  -        } catch (SAXParseException e) {
  -            log(sm.getString("contextConfig.defaultParse"), e);
  -            log(sm.getString("contextConfig.defaultPosition",
  -                             "" + e.getLineNumber(),
  -                             "" + e.getColumnNumber()));
  -            ok = false;
  -        } catch (Exception e) {
  -            log(sm.getString("contextConfig.defaultParse"), e);
  -            ok = false;
  -        } finally {
  -            try {
  -                stream.close();
  -            } catch (IOException e) {
  -                log(sm.getString("contextConfig.defaultClose"), e);
  +                webDigester.clear();
  +                webDigester.push(context);
  +                webDigester.parse(stream);
  +            } catch (SAXParseException e) {
  +                log(sm.getString("contextConfig.defaultParse"), e);
  +                log(sm.getString("contextConfig.defaultPosition",
  +                                 "" + e.getLineNumber(),
  +                                 "" + e.getColumnNumber()));
  +                ok = false;
  +            } catch (Exception e) {
  +                log(sm.getString("contextConfig.defaultParse"), e);
  +                ok = false;
  +            } finally {
  +                try {
  +                    stream.close();
  +                } catch (IOException e) {
  +                    log(sm.getString("contextConfig.defaultClose"), e);
  +                }
               }
           }
   
  @@ -794,71 +787,71 @@
       private void tldConfig() {
   
           // Acquire a Digester to use for parsing
  -        Digester digester = createTldDigester();
  +        synchronized (tldDigester) {
   
  -        // First, scan tag libraries declared in our deployment descriptor
  -        if (debug >= 1)
  -            log("Scanning web.xml tag libraries");
  -        ArrayList resourcePaths = new ArrayList(); // Already processed TLDs
  -        String taglibs[] = context.findTaglibs();
  -        for (int i = 0; i < taglibs.length; i++) {
  -
  -            // Calculate the resource path of the next tag library to check
  -            String resourcePath = context.findTaglib(taglibs[i]);
  -            if (!resourcePath.startsWith("/"))
  -                resourcePath = "/WEB-INF/web.xml/../" + resourcePath;
  -            if (debug >= 2)
  -                log("  URI='" + taglibs[i] + "', ResourcePath='" +
  -                    resourcePath + "'");
  -            if (resourcePaths.contains(resourcePath)) {
  +            // First, scan tag libraries declared in our deployment descriptor
  +            if (debug >= 1)
  +                log("Scanning web.xml tag libraries");
  +            ArrayList resourcePaths = new ArrayList(); // Already done TLDs
  +            String taglibs[] = context.findTaglibs();
  +            for (int i = 0; i < taglibs.length; i++) {
  +                
  +                // Calculate the resource path of the next tag library to check
  +                String resourcePath = context.findTaglib(taglibs[i]);
  +                if (!resourcePath.startsWith("/"))
  +                    resourcePath = "/WEB-INF/web.xml/../" + resourcePath;
                   if (debug >= 2)
  -                    log("    Already processed");
  -                continue;
  -            }
  -            resourcePaths.add(resourcePath);
  -
  -            // Process either a JAR file or a TLD at this location
  -            if (!tldConfigJar(resourcePath, digester))
  -                tldConfigTld(resourcePath, digester);
  +                    log("  URI='" + taglibs[i] + "', ResourcePath='" +
  +                        resourcePath + "'");
  +                if (resourcePaths.contains(resourcePath)) {
  +                    if (debug >= 2)
  +                        log("    Already processed");
  +                    continue;
  +                }
  +                resourcePaths.add(resourcePath);
   
  -        }
  +                // Process either a JAR file or a TLD at this location
  +                if (!tldConfigJar(resourcePath, tldDigester))
  +                    tldConfigTld(resourcePath, tldDigester);
   
  -        DirContext resources = context.getResources();
  +            }
   
  -        // Second, scan tag libraries defined in tld files in /WEB-INF
  -        if (debug >= 1)
  -            log("Scanning TLD files in /WEB-INF");
  -        String webinfName = "/WEB-INF";
  -        // Looking up directory /WEB-INF in the context
  -        try {
  -            NamingEnumeration enum = resources.list(webinfName);
  -            while (enum.hasMoreElements()) {
  -                NameClassPair ncPair = (NameClassPair) enum.nextElement();
  -                String filename = webinfName + "/" + ncPair.getName();
  -                if (!filename.endsWith(".tld"))
  -                    continue;
  -                tldConfigTld(filename, digester);
  +            // Second, scan tag libraries defined in tld files in /WEB-INF
  +            if (debug >= 1)
  +                log("Scanning TLD files in /WEB-INF");
  +            DirContext resources = context.getResources();
  +            String webinfName = "/WEB-INF";
  +            // Looking up directory /WEB-INF in the context
  +            try {
  +                NamingEnumeration enum = resources.list(webinfName);
  +                while (enum.hasMoreElements()) {
  +                    NameClassPair ncPair = (NameClassPair) enum.nextElement();
  +                    String filename = webinfName + "/" + ncPair.getName();
  +                    if (!filename.endsWith(".tld"))
  +                        continue;
  +                    tldConfigTld(filename, tldDigester);
  +                }
  +            } catch (NamingException e) {
  +                // Silent catch: it's valid that no /WEB-INF directory exists
               }
  -        } catch (NamingException e) {
  -            // Silent catch: it's valid that no /WEB-INF directory exists
  -        }
   
  -        // Third, scan tag libraries defined in JAR files
  -        if (debug >= 1)
  -            log("Scanning library JAR files");
  -        String libName = "/WEB-INF/lib";
  -        // Looking up directory /WEB-INF/lib in the context
  -        try {
  -            NamingEnumeration enum = resources.list(libName);
  -            while (enum.hasMoreElements()) {
  -                NameClassPair ncPair = (NameClassPair) enum.nextElement();
  -                String filename = libName + "/" + ncPair.getName();
  -                if (!filename.endsWith(".jar"))
  -                    continue;
  -                tldConfigJar(filename, digester);
  +            // Third, scan tag libraries defined in JAR files
  +            if (debug >= 1)
  +                log("Scanning library JAR files");
  +            String libName = "/WEB-INF/lib";
  +            // Looking up directory /WEB-INF/lib in the context
  +            try {
  +                NamingEnumeration enum = resources.list(libName);
  +                while (enum.hasMoreElements()) {
  +                    NameClassPair ncPair = (NameClassPair) enum.nextElement();
  +                    String filename = libName + "/" + ncPair.getName();
  +                    if (!filename.endsWith(".jar"))
  +                        continue;
  +                    tldConfigJar(filename, tldDigester);
  +                }
  +            } catch (NamingException e) {
  +                // Silent catch: it's ok that no /WEB-INF/lib directory exists
               }
  -        } catch (NamingException e) {
  -            // Silent catch: it's valid that no /WEB-INF/lib directory exists
           }
   
       }
  @@ -898,6 +891,7 @@
                           "): Processing entry '" + name + "'");
                   stream = jarFile.getInputStream(entry);
                   synchronized (digester) {
  +                    digester.clear();
                       digester.push(context);
                       digester.parse(stream);
                   }
  @@ -946,6 +940,7 @@
               if (stream == null)
                   return (false);
               synchronized (digester) {
  +                digester.clear();
                   digester.push(context);
                   digester.parse(stream);
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to