@@ -248,7 +248,8 @@ public void setContext(String path, String[] welcomeResources,
248248 * @param context Context object
249249 * @param welcomeResources Welcome files defined for this context
250250 * @param resources Static resources of the context
251- * @deprecated Use {@link #addContextVersion(String, Object, String, String, Object, String[], javax.naming.Context, Collection)}
251+ * @deprecated Use {@link #addContextVersion(String, Object, String, String, Object, String[],
252+ * javax.naming.Context, Collection, boolean, boolean)}
252253 */
253254 @ Deprecated
254255 public void addContextVersion (String hostName , Object host , String path ,
@@ -258,6 +259,7 @@ public void addContextVersion(String hostName, Object host, String path,
258259 welcomeResources , resources , null );
259260 }
260261
262+
261263 /**
262264 * Add a new Context to an existing Host.
263265 *
@@ -269,10 +271,36 @@ public void addContextVersion(String hostName, Object host, String path,
269271 * @param welcomeResources Welcome files defined for this context
270272 * @param resources Static resources of the context
271273 * @param wrappers Information on wrapper mappings
274+ * @deprecated Use {@link #addContextVersion(String, Object, String, String, Object, String[],
275+ * javax.naming.Context, Collection, boolean, boolean)}
272276 */
277+ @ Deprecated
273278 public void addContextVersion (String hostName , Object host , String path ,
274279 String version , Object context , String [] welcomeResources ,
275280 javax .naming .Context resources , Collection <WrapperMappingInfo > wrappers ) {
281+ addContextVersion (hostName , host , path , version , context , welcomeResources , resources ,
282+ wrappers , false , false );
283+ }
284+
285+
286+ /**
287+ * Add a new Context to an existing Host.
288+ *
289+ * @param hostName Virtual host name this context belongs to
290+ * @param host Host object
291+ * @param path Context path
292+ * @param version Context version
293+ * @param context Context object
294+ * @param welcomeResources Welcome files defined for this context
295+ * @param resources Static resources of the context
296+ * @param wrappers Information on wrapper mappings
297+ * @param mapperContextRootRedirectEnabled Mapper does context root redirects
298+ * @param mapperDirectoryRedirectEnabled Mapper does directory redirects
299+ */
300+ public void addContextVersion (String hostName , Object host , String path ,
301+ String version , Object context , String [] welcomeResources ,
302+ javax .naming .Context resources , Collection <WrapperMappingInfo > wrappers ,
303+ boolean mapperContextRootRedirectEnabled , boolean mapperDirectoryRedirectEnabled ) {
276304
277305 Host mappedHost = exactFind (hosts , hostName );
278306 if (mappedHost == null ) {
@@ -294,6 +322,9 @@ public void addContextVersion(String hostName, Object host, String path,
294322 newContextVersion .slashCount = slashCount ;
295323 newContextVersion .welcomeResources = welcomeResources ;
296324 newContextVersion .resources = resources ;
325+ newContextVersion .mapperContextRootRedirectEnabled = mapperContextRootRedirectEnabled ;
326+ newContextVersion .mapperDirectoryRedirectEnabled = mapperDirectoryRedirectEnabled ;
327+
297328 if (wrappers != null ) {
298329 addWrappers (newContextVersion , wrappers );
299330 }
@@ -904,7 +935,8 @@ private final void internalMapWrapper(ContextVersion contextVersion,
904935 }
905936 }
906937
907- if (mappingData .wrapper == null && noServletPath ) {
938+ if (mappingData .wrapper == null && noServletPath &&
939+ contextVersion .mapperContextRootRedirectEnabled ) {
908940 // The path is empty, redirect to "/"
909941 mappingData .redirectPath .setChars
910942 (path .getBuffer (), pathOffset , pathEnd -pathOffset );
@@ -1032,7 +1064,8 @@ private final void internalMapWrapper(ContextVersion contextVersion,
10321064 } catch (NamingException nex ) {
10331065 // Swallow, since someone else handles the 404
10341066 }
1035- if (file != null && file instanceof DirContext ) {
1067+ if (file != null && file instanceof DirContext &&
1068+ contextVersion .mapperDirectoryRedirectEnabled ) {
10361069 // Note: this mutates the path: do not do any processing
10371070 // after this (since we set the redirectPath, there
10381071 // shouldn't be any)
@@ -1049,7 +1082,6 @@ private final void internalMapWrapper(ContextVersion contextVersion,
10491082
10501083 path .setOffset (pathOffset );
10511084 path .setEnd (pathEnd );
1052-
10531085 }
10541086
10551087
@@ -1684,6 +1716,8 @@ protected static final class ContextVersion extends MapElement {
16841716 public Wrapper [] wildcardWrappers = new Wrapper [0 ];
16851717 public Wrapper [] extensionWrappers = new Wrapper [0 ];
16861718 public int nesting = 0 ;
1719+ public boolean mapperContextRootRedirectEnabled = false ;
1720+ public boolean mapperDirectoryRedirectEnabled = false ;
16871721 private volatile boolean paused ;
16881722
16891723 public ContextVersion () {
0 commit comments