Author: markt
Date: Fri Jun 1 10:19:01 2012
New Revision: 1345041
URL: http://svn.apache.org/viewvc?rev=1345041&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/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Tomcat.java
tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestTomcat.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1345039
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Tomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1345041&r1=1345040&r2=1345041&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Tomcat.java Fri Jun
1 10:19:01 2012
@@ -826,7 +826,6 @@ public class Tomcat {
*/
public static class ExistingStandardWrapper extends StandardWrapper {
private final Servlet existing;
- boolean init = false;
@SuppressWarnings("deprecation")
public ExistingStandardWrapper( Servlet existing ) {
@@ -850,9 +849,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/tc7.0.x/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=1345041&r1=1345040&r2=1345041&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestTomcat.java
(original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestTomcat.java Fri
Jun 1 10:19:01 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());
+ }
}
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1345041&r1=1345040&r2=1345041&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Fri Jun 1 10:19:01 2012
@@ -165,6 +165,10 @@
to contain a <code>role-link</code> element. (markt)
</fix>
<fix>
+ <bug>53301</bug>: Prevent double initialization of pre-created Servlet
+ instances when used in embedded mode. (markt)
+ </fix>
+ <fix>
<bug>53322</bug>: When processing resource injection, correctly infer
property name from its setter method if the name starts with several
uppercase characters. (kkolinko)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]