Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51644
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Aug 2011 17:57:25 +0000 (17:57 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Aug 2011 17:57:25 +0000 (17:57 +0000)
Annotation scanning was broken for contexts with a multi-level context path such as /a/b

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1156276 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/resources/DirContextURLConnection.java

index 80d8343..3bbff1c 100644 (file)
@@ -436,14 +436,20 @@ public class DirContextURLConnection
                 // This will be of the form /<hostname>/<contextpath>/file name
                 // if <contextpath> is not empty otherwise this will be of the
                 // form /<hostname>/file name
-                // Strip off the hostname and the contextpath
+                // Strip off the hostname and the contextpath (note that context
+                // path may contain '/'
                 int start;
-                if(context instanceof ProxyDirContext &&
-                        "".equals(((ProxyDirContext)context).getContextPath())){
-                    start = file.indexOf('/',1);
-                }
-                else
+                if (context instanceof ProxyDirContext) {
+                    String cp = ((ProxyDirContext)context).getContextPath();
+                    String h = ((ProxyDirContext)context).getHostName();
+                    if ("".equals(cp)) {
+                        start = h.length() + 2;
+                    } else {
+                        start = h.length() + cp.length() + 2;
+                    }
+                } else {
                     start = file.indexOf('/', file.indexOf('/', 1) + 1);
+                }
                 
                 NamingEnumeration<NameClassPair> enumeration =
                     context.list(file.substring(start));