* @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());
}
* 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());
}
* 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);
+ }
/**
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
* @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);
/**
* 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);
* 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);
--- /dev/null
+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");
+ }
+
+ }
+}