You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/05/21 18:34:27 UTC
svn commit: r1484862 - in /tomcat/trunk:
java/org/apache/catalina/startup/ContextConfig.java
test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Author: markt
Date: Tue May 21 16:34:27 2013
New Revision: 1484862
URL: http://svn.apache.org/r1484862
Log:
Make deletion of the copied WARs used for anti-resource locking more robust if the context fails to start (there were some circumstances where the original WAR could get deleted). Add some test cases to check this.
Modified:
tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1484862&r1=1484861&r2=1484862&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Tue May 21 16:34:27 2013
@@ -213,6 +213,12 @@ public class ContextConfig implements Li
/**
+ * Anti-locking docBase
+ */
+ private String antiLockingDocBase = null;
+
+
+ /**
* Map of ServletContainerInitializer to classes they expressed interest in.
*/
protected final Map<ServletContainerInitializer, Set<Class<?>>> initializerClassMap =
@@ -325,16 +331,9 @@ public class ContextConfig implements Li
} else if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
// Restore docBase for management tools
if (originalDocBase != null) {
- String docBase = context.getDocBase();
context.setDocBase(originalDocBase);
- originalDocBase = docBase;
}
} else if (event.getType().equals(Lifecycle.CONFIGURE_STOP_EVENT)) {
- if (originalDocBase != null) {
- String docBase = context.getDocBase();
- context.setDocBase(originalDocBase);
- originalDocBase = docBase;
- }
configureStop();
} else if (event.getType().equals(Lifecycle.AFTER_INIT_EVENT)) {
init();
@@ -714,11 +713,8 @@ public class ContextConfig implements Li
if (docBase == null) {
return;
}
- if (originalDocBase == null) {
- originalDocBase = docBase;
- } else {
- docBase = originalDocBase;
- }
+ originalDocBase = docBase;
+
File docBaseFile = new File(docBase);
if (!docBaseFile.isAbsolute()) {
docBaseFile = new File(host.getAppBaseFile(), docBase);
@@ -745,12 +741,12 @@ public class ContextConfig implements Li
+ "] setting docBase to " + file);
}
+ antiLockingDocBase = file.getAbsolutePath();
// Cleanup just in case an old deployment is lying around
ExpandWar.delete(file);
if (ExpandWar.copy(docBaseFile, file)) {
- context.setDocBase(file.getAbsolutePath());
+ context.setDocBase(antiLockingDocBase);
}
-
}
}
@@ -999,8 +995,8 @@ public class ContextConfig implements Li
// Remove (partially) folders and files created by antiLocking
Host host = (Host) context.getParent();
String docBase = context.getDocBase();
- if ((docBase != null) && (originalDocBase != null)) {
- File docBaseFile = new File(docBase);
+ if (antiLockingDocBase != null) {
+ File docBaseFile = new File(antiLockingDocBase);
if (!docBaseFile.isAbsolute()) {
docBaseFile = new File(host.getAppBaseFile(), docBase);
}
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java?rev=1484862&r1=1484861&r2=1484862&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java Tue May 21 16:34:27 2013
@@ -55,6 +55,8 @@ public class TestHostConfigAutomaticDepl
new File("test/deployment/contextUnpackWARTrue.war");
private static final File WAR_SOURCE =
new File("test/deployment/noContext.war");
+ private static final File WAR_BROKEN_SOURCE =
+ new File("test/deployment/broken.war");
private static final File DIR_XML_SOURCE =
new File("test/deployment/dirContext");
private static final File DIR_SOURCE =
@@ -1563,6 +1565,40 @@ public class TestHostConfigAutomaticDepl
}
+ @Test
+ public void testBrokenAppWithAntiLockingF() throws Exception {
+ testBrokenAppWithAntiLocking(false);
+ }
+
+ @Test
+ public void testBrokenAppWithAntiLockingT() throws Exception {
+ testBrokenAppWithAntiLocking(true);
+ }
+
+ private void testBrokenAppWithAntiLocking(boolean unpackWARs)
+ throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+ StandardHost host = (StandardHost) tomcat.getHost();
+
+ host.setUnpackWARs(unpackWARs);
+
+ File war = createWar(WAR_BROKEN_SOURCE, false);
+ createXmlInConfigBaseForExternal(war, true);
+
+ File dir = new File(host.getAppBaseFile(), APP_NAME.getBaseName());
+
+ tomcat.start();
+
+ // Simulate deploy on start-up
+ tomcat.getHost().backgroundProcess();
+
+ Assert.assertTrue(war.isFile());
+ if (unpackWARs) {
+ Assert.assertTrue(dir.isDirectory());
+ }
+ }
+
private File createDirInAppbase(boolean withXml) throws IOException {
File dir = new File(getTomcatInstance().getHost().getAppBaseFile(),
APP_NAME.getBaseName());
@@ -1608,6 +1644,11 @@ public class TestHostConfigAutomaticDepl
}
private File createXmlInConfigBaseForExternal(File ext) throws IOException {
+ return createXmlInConfigBaseForExternal(ext, false);
+ }
+
+ private File createXmlInConfigBaseForExternal(File ext, boolean antiLocking)
+ throws IOException {
File xml = new File(getTomcatInstance().getHost().getConfigBaseFile(),
APP_NAME + ".xml");
File parent = xml.getParentFile();
@@ -1616,9 +1657,16 @@ public class TestHostConfigAutomaticDepl
}
try (FileOutputStream fos = new FileOutputStream(xml)) {
- fos.write(("<Context sessionCookieName=\"" + XML_COOKIE_NAME +
- "\" docBase=\"" + ext.getAbsolutePath() +
- "\" />").getBytes(B2CConverter.ISO_8859_1));
+ StringBuilder context = new StringBuilder();
+ context.append("<Context sessionCookieName=\"");
+ context.append(XML_COOKIE_NAME);
+ context.append("\" docBase=\"");
+ context.append(ext.getAbsolutePath());
+ if (antiLocking) {
+ context.append("\" antiResourceLocking=\"true");
+ }
+ context.append("\" />");
+ fos.write(context.toString().getBytes(B2CConverter.ISO_8859_1));
}
return xml;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org