Skip to content

Commit be5909d

Browse files
author
Konstantin Kolinko
committed
Alternative fix for aliases support issue git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1604940 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6365653 commit be5909d

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

java/org/apache/catalina/mapper/Mapper.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ public synchronized void removeHostAlias(String alias) {
181181

182182
}
183183

184+
/**
185+
* Replace {@link MappedHost#contextList} field in <code>realHost</code> and
186+
* all its aliases with a new value.
187+
*/
188+
private void updateContextList(MappedHost realHost,
189+
ContextList newContextList) {
190+
191+
// The real host and all the aliases map to the same host object
192+
Host object = realHost.object;
193+
for (MappedHost host : hosts) {
194+
if (host.object == object) {
195+
host.contextList = newContextList;
196+
}
197+
}
198+
}
184199

185200
/**
186201
* Add a new Context to an existing Host.
@@ -211,13 +226,16 @@ public void addContextVersion(String hostName, Host host, String path,
211226
ContextVersion newContextVersion = new ContextVersion(version,
212227
path, slashCount, context, resources, welcomeResources);
213228

214-
MappedContext mappedContext = exactFind(
215-
mappedHost.contextList.contexts, path);
229+
ContextList contextList = mappedHost.contextList;
230+
MappedContext mappedContext = exactFind(contextList.contexts, path);
216231
if (mappedContext == null) {
217232
mappedContext = new MappedContext(path, newContextVersion);
218-
mappedHost.contextList = mappedHost.contextList.addContext(
233+
ContextList newContextList = contextList.addContext(
219234
mappedContext, slashCount);
220-
contextObjectToContextVersionMap.put(context, newContextVersion);
235+
if (newContextList != null) {
236+
updateContextList(mappedHost, newContextList);
237+
contextObjectToContextVersionMap.put(context, newContextVersion);
238+
}
221239
} else {
222240
ContextVersion[] contextVersions = mappedContext.versions;
223241
ContextVersion[] newContextVersions = new ContextVersion[contextVersions.length + 1];
@@ -251,7 +269,8 @@ public void removeContextVersion(Context ctxt, String hostName,
251269
}
252270

253271
synchronized (host) {
254-
MappedContext context = exactFind(host.contextList.contexts, path);
272+
ContextList contextList = host.contextList;
273+
MappedContext context = exactFind(contextList.contexts, path);
255274
if (context == null) {
256275
return;
257276
}
@@ -262,7 +281,10 @@ public void removeContextVersion(Context ctxt, String hostName,
262281
if (removeMap(contextVersions, newContextVersions, version)) {
263282
if (newContextVersions.length == 0) {
264283
// Remove the context
265-
host.contextList = host.contextList.removeContext(path);
284+
ContextList newContextList = contextList.removeContext(path);
285+
if (newContextList != null) {
286+
updateContextList(host, newContextList);
287+
}
266288
} else {
267289
context.versions = newContextVersions;
268290
}
@@ -1463,7 +1485,7 @@ public ContextList addContext(MappedContext mappedContext,
14631485
return new ContextList(newContexts, Math.max(nesting,
14641486
slashCount));
14651487
}
1466-
return this;
1488+
return null;
14671489
}
14681490

14691491
public ContextList removeContext(String path) {
@@ -1475,7 +1497,7 @@ public ContextList removeContext(String path) {
14751497
}
14761498
return new ContextList(newContexts, newNesting);
14771499
}
1478-
return this;
1500+
return null;
14791501
}
14801502
}
14811503

0 commit comments

Comments
 (0)