ekbush 2002/10/15 10:37:25
Modified: src/share/org/apache/struts/util RequestUtils.java
Log:
Change RequestUtils.selectApplication so that it looks for an exact match
rather than using the startsWith criteria. This fixes a problem where
an incorrect module would be selected that either became aparant when
the application had modules where the name of one could be used as the "root"
of the other. The bug also manifests itself when an action is invoked from
the default module, which has a path that could be interpreted as a "root" of
a non-default module.
Ex: modules /foo and /foobar
module /foo and action /foo in the default module
PR: 12702
Revision Changes Path
1.61 +33 -11
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- RequestUtils.java 14 Oct 2002 18:16:19 -0000 1.60
+++ RequestUtils.java 15 Oct 2002 17:37:25 -0000 1.61
@@ -1424,19 +1424,41 @@
// Acquire the path used to compute the module
String matchPath = (String)
request.getAttribute(RequestProcessor.INCLUDE_SERVLET_PATH);
+
if (matchPath == null) {
matchPath = request.getServletPath();
}
- // Match against the list of module prefixes
- String prefix = "";
- String prefixes[] = getApplicationPrefixes(context);
- for (int i = 0; i < prefixes.length; i++) {
- if (matchPath.startsWith(prefixes[i])) {
- prefix = prefixes[i];
- break;
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Selecting module for path " + matchPath);
+ }
+
+ String prefix = ""; // Initialize prefix before we try lookup
+ String prefixes[] =
+ getApplicationPrefixes(context); // Get all other possible prefixes
+ int lastSlash = 0; // Initialize before loop
+
+ while (prefix.equals("") &&
+ ((lastSlash = matchPath.lastIndexOf("/")) != 0)) {
+
+ // We may be in a non-default sub-app. Try to get it's prefix.
+ matchPath = matchPath.substring(0, lastSlash);
+
+ // Match against the list of module prefixes
+ for (int i = 0; i < prefixes.length; i++) {
+ if (matchPath.equals(prefixes[i])) {
+ prefix = prefixes[i];
+ break;
+ }
}
}
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Activating module " +
+ (prefix.equals("") ? "default" : prefix));
+ }
// Expose the resources for this module
selectApplication(prefix, request, context);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>