tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1345039 - in /tomcat/trunk: java/org/apache/catalina/startup/Tomcat.java test/org/apache/catalina/startup/TestTomcat.java
Date Fri, 01 Jun 2012 10:16:51 GMT
Author: markt
Date: Fri Jun  1 10:16:50 2012
New Revision: 1345039

URL: http://svn.apache.org/viewvc?rev=1345039&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53301
Prevent double initialisation of servlets when using existing servlet instances with embedded
Tomcat

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
    tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1345039&r1=1345038&r2=1345039&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Fri Jun  1 10:16:50 2012
@@ -797,7 +797,6 @@ public class Tomcat {
      */
     public static class ExistingStandardWrapper extends StandardWrapper {
         private final Servlet existing;
-        boolean init = false;
 
         @SuppressWarnings("deprecation")
         public ExistingStandardWrapper( Servlet existing ) {
@@ -821,9 +820,9 @@ public class Tomcat {
                 instance.init(facade);
                 return instance;
             } else {
-                if (!init) {
+                if (!instanceInitialized) {
                     existing.init(facade);
-                    init = true;
+                    instanceInitialized = true;
                 }
                 return existing;
             }

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=1345039&r1=1345038&r2=1345039&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Fri Jun  1 10:16:50 2012
@@ -28,10 +28,12 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -159,6 +161,34 @@ public class TestTomcat extends TomcatBa
     }
 
     /**
+     * Simple servlet to test initialization of servlet instances.
+     */
+    private static class InitCount extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private AtomicInteger callCount = new AtomicInteger(0);
+
+        @Override
+        public void init() throws ServletException {
+            super.init();
+            callCount.incrementAndGet();
+        }
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/plain");
+            resp.getWriter().print("OK");
+        }
+
+        public int getCallCount() {
+            return callCount.intValue();
+        }
+    }
+
+
+    /**
      * Simple Realm that uses a configurable {@link Map} to link user names and
      * passwords.
      */
@@ -397,4 +427,24 @@ public class TestTomcat extends TomcatBa
         }
         assertNull(e);
     }
+
+    @Test
+    public void testBug53301() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // Must have a real docBase - just use temp
+        org.apache.catalina.Context ctx =
+            tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+        InitCount initCount = new InitCount();
+        Tomcat.addServlet(ctx, "initCount", initCount);
+        ctx.addServletMapping("/", "initCount");
+
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
+        assertEquals("OK", res.toString());
+
+        assertEquals(1, initCount.getCallCount());
+    }
 }



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


Mime
View raw message