You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/03/09 21:33:27 UTC
svn commit: r921110 - in /tomcat/trunk: java/org/apache/naming/resources/
test/org/apache/naming/ test/org/apache/naming/resources/
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<Binding> listBindings(Name name)
+ public final NamingEnumeration<Binding> 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<Binding> listBindings(String name)
- throws NamingException;
+ public final NamingEnumeration<Binding> 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<Binding> 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<Binding> listBindings(String name)
+ protected NamingEnumeration<Binding> 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<Binding> listBindings(String name)
+ protected NamingEnumeration<Binding> 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.
- * <p>
- * 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<Binding> 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<String> 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