Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 91077 invoked from network); 9 Mar 2010 20:34:17 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Mar 2010 20:34:17 -0000 Received: (qmail 11823 invoked by uid 500); 9 Mar 2010 20:33:49 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 11739 invoked by uid 500); 9 Mar 2010 20:33:49 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 11729 invoked by uid 99); 9 Mar 2010 20:33:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 20:33:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 20:33:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C70C82388906; Tue, 9 Mar 2010 20:33:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r921110 - in /tomcat/trunk: java/org/apache/naming/resources/ test/org/apache/naming/ test/org/apache/naming/resources/ Date: Tue, 09 Mar 2010 20:33:27 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100309203327.C70C82388906@eris.apache.org> Author: markt Date: Tue Mar 9 20:33:27 2010 New Revision: 921110 URL: http://svn.apache.org/viewvc?rev=921110&view=rev Log: Make StandardContext aliases work with ServletContext.getResourcePaths() Added: tomcat/trunk/test/org/apache/naming/ tomcat/trunk/test/org/apache/naming/resources/ tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java (with props) Modified: tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java Modified: tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java?rev=921110&r1=921109&r2=921110&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java Tue Mar 9 20:33:27 2010 @@ -366,7 +366,7 @@ public abstract class BaseDirContext imp * @return the object bound to name * @exception NamingException if a naming exception is encountered */ - public Object lookup(Name name) + public final Object lookup(Name name) throws NamingException { return lookup(name.toString()); } @@ -566,7 +566,7 @@ public abstract class BaseDirContext imp * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ - public NamingEnumeration listBindings(Name name) + public final NamingEnumeration listBindings(Name name) throws NamingException { return listBindings(name.toString()); } @@ -581,8 +581,16 @@ public abstract class BaseDirContext imp * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ - public abstract NamingEnumeration listBindings(String name) - throws NamingException; + public final NamingEnumeration listBindings(String name) + throws NamingException { + if (!aliases.isEmpty()) { + AliasResult result = findAlias(name); + if (result.dirContext != null) { + return result.dirContext.listBindings(result.aliasName); + } + } + return doListBindings(name); + } /** @@ -1365,6 +1373,9 @@ public abstract class BaseDirContext imp protected abstract Object doLookup(String name) throws NamingException; + protected abstract NamingEnumeration doListBindings(String name) + throws NamingException; + protected abstract String doGetRealPath(String name); // -------------------------------------------------------- Private Methods Modified: tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java?rev=921110&r1=921109&r2=921110&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java Tue Mar 9 20:33:27 2010 @@ -320,7 +320,7 @@ public class FileDirContext extends Base * @exception NamingException if a naming exception is encountered */ @Override - public NamingEnumeration listBindings(String name) + protected NamingEnumeration doListBindings(String name) throws NamingException { File file = file(name); Modified: tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java?rev=921110&r1=921109&r2=921110&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java Tue Mar 9 20:33:27 2010 @@ -187,30 +187,16 @@ public class WARDirContext extends BaseD /** * Retrieves the named object. * - * @param name the name of the object to look up + * @param strName the name of the object to look up * @return the object bound to name * @exception NamingException if a naming exception is encountered */ @Override - protected Object doLookup(String name) + protected Object doLookup(String strName) throws NamingException { - return lookup(new CompositeName(name)); - } + Name name = new CompositeName(strName); - /** - * Retrieves the named object. If name is empty, returns a new instance - * of this context (which represents the same naming context as this - * context, but its environment may be modified independently and it may - * be accessed concurrently). - * - * @param name the name of the object to look up - * @return the object bound to name - * @exception NamingException if a naming exception is encountered - */ - @Override - public Object lookup(Name name) - throws NamingException { if (name.isEmpty()) return this; Entry entry = treeLookup(name); @@ -318,34 +304,17 @@ public class WARDirContext extends BaseD * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * - * @param name the name of the context to list + * @param strName the name of the context to list * @return an enumeration of the bindings in this context. * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ @Override - public NamingEnumeration listBindings(String name) + protected NamingEnumeration doListBindings(String strName) throws NamingException { - return listBindings(new CompositeName(name)); - } - + + Name name = new CompositeName(strName); - /** - * Enumerates the names bound in the named context, along with the - * objects bound to them. The contents of any subcontexts are not - * included. - *

- * If a binding is added to or removed from this context, its effect on - * an enumeration previously returned is undefined. - * - * @param name the name of the context to list - * @return an enumeration of the bindings in this context. - * Each element of the enumeration is of type Binding. - * @exception NamingException if a naming exception is encountered - */ - @Override - public NamingEnumeration listBindings(Name name) - throws NamingException { if (name.isEmpty()) return new NamingContextBindingsEnumeration(list(entries).iterator(), this); Added: tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java?rev=921110&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java (added) +++ tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java Tue Mar 9 20:33:27 2010 @@ -0,0 +1,89 @@ +package org.apache.naming.resources; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestBaseDirContext extends TomcatBaseTest { + + public void testDirContextAliases() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + StandardContext ctx = (StandardContext) + tomcat.addContext("/", System.getProperty("java.io.tmpdir")); + + File lib = new File("webapps/examples/WEB-INF/lib"); + ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath()); + + Tomcat.addServlet(ctx, "test", new TestServlet()); + ctx.addServletMapping("/", "test"); + + tomcat.start(); + + ByteChunk res = getUrl("http://localhost:" + getPort() + "/"); + + String result = res.toString(); + + assertTrue(result.indexOf("00-PASS") > -1); + assertTrue(result.indexOf("01-PASS") > -1); + assertTrue(result.indexOf("02-PASS") > -1); + } + + + /** + * Looks for the JSTL JARs in WEB-INF/lib. + */ + public static class TestServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + + resp.setContentType("text/plain"); + + ServletContext context = getServletContext(); + + // Check resources individually + URL url = context.getResource("/WEB-INF/lib/jstl.jar"); + if (url != null) { + resp.getWriter().write("00-PASS\n"); + } + + url = context.getResource("/WEB-INF/lib/standard.jar"); + if (url != null) { + resp.getWriter().write("01-PASS\n"); + } + + // Check a directory listing + Set libs = context.getResourcePaths("/WEB-INF/lib"); + if (libs == null) { + return; + } + + if (!libs.contains("/WEB-INF/lib/jstl.jar")) { + return; + } + if (!libs.contains("/WEB-INF/lib/standard.jar")) { + return; + } + + resp.getWriter().write("02-PASS\n"); + } + + } +} Propchange: tomcat/trunk/test/org/apache/naming/resources/TestBaseDirContext.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org