Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370294

Summary: ServerInstance.getContextFilePath() incorrectly calculates multi level context file path
Product: [WebTools] WTP ServerTools Reporter: Mike Youngstrom <youngm>
Component: jst.serverAssignee: jst.server <jst.server-inbox>
Status: NEW --- QA Contact: Elson Yuen <eyuen7>
Severity: normal    
Priority: P3 CC: larryisaacs
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mike Youngstrom CLA 2012-02-01 01:10:43 EST
Build Identifier: Indigo SR1

ServerInstance.getContextFilePath() fails to calculate correct context file path for multi level context roots.  It doesn't correctly replace '/' with '#'.

This problem results in orphaned context roots finding their way in the conf/Catalina/localhost directory after TomcatConfiguration.cleanupServer() invocation.

This problem requires a clean of the server to fix it.

Here is a possible simple patch:

	public IPath getContextFilePath(IPath baseDir, Context context) {
		if (context == null)
			throw new IllegalArgumentException(Messages.errorXMLNullContextArg);
		status = Status.OK_STATUS;
		if (host == null && getHost() == null)
			return null;

		IPath contextFilePath = null;
		IPath contextDir = getContextXmlDirectory(baseDir.append("conf"));
		String name = context.getPath();
		if (name != null) {
			if (name.startsWith("/"))
				name = name.substring(1);
			if (name.length() == 0)
				name = "ROOT";
                        name.replaceAll("/", "#"); //Support multi level context roots.
			contextFilePath = contextDir.append(name + ".xml");
		}
		else {
			// TODO Set error status
		}
		return contextFilePath;
	}



Reproducible: Always

Steps to Reproduce:
1. Create a Tomcat Server.
2. Enable Publish Module Context separately
3. Add a web project with a multi level context root (e.g. some/path)
4. Look at the publish location for this server.  Notice a context xml file in conf/Catalina/localhost (e.g. some#path.xml)
5. Change the context root through the Server Properties->Modules tab. (e.g. some/path2)
6. Look in published location.  Note that the some#path.xml file is still there.
Comment 1 Mike Youngstrom CLA 2012-02-01 01:13:05 EST
Sorry forgot to detail that this is an issue with the Tomcat Server Adapter.
Comment 2 Mike Youngstrom CLA 2012-02-01 01:13:42 EST
org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance.getContextFilePath()