Bug 53854 - DefaultServlet directory listings for aliased directories do not seem to work
Summary: DefaultServlet directory listings for aliased directories do not seem to work
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.30
Hardware: All All
: P2 minor (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-11 20:28 UTC by Daniel Mikusa
Modified: 2012-09-30 19:49 UTC (History)
0 users



Attachments
Patch to DefaultServlet to workaround the error. (1005 bytes, patch)
2012-09-11 20:50 UTC, Daniel Mikusa
Details | Diff
Updated patch, works with BaseDirContext and FileDirContext (1.72 KB, patch)
2012-09-18 16:37 UTC, Daniel Mikusa
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Mikusa 2012-09-11 20:28:09 UTC
The following situation does not seem to work.

1.) In a Context, add an alias to a directory.
2.) Enable directory listings on the DefaultServlet.
3.) Try to view the directory listing of the alias directory.

Example:

conf/context.xml:

  <Context aliases="/files=/my/downloads">
  ...
  </Context>

conf/web.xml:

    ...
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    ...

contents of the directory "/my/downloads":

  -rw-r--r--@ 1 daniel  staff  8156824 Sep 10 09:15 apache-tomcat-7.0.30.zip

URL works:

http://localhost:8080/files/apache-tomcat-7.0.30.zip

URL does not work:

http://localhost:8080/files/

The URL that does not work fails with the error:

SEVERE: Servlet.service() for servlet [default] in context with path [/] threw exception [Error accessing resource] with root cause
javax.naming.NameNotFoundException: Resource /files/ not found
	at org.apache.naming.resources.FileDirContext.list(FileDirContext.java:303)
	at org.apache.naming.resources.ProxyDirContext.list(ProxyDirContext.java:512)
	at org.apache.catalina.servlets.DefaultServlet.renderHtml(DefaultServlet.java:1458)
	at org.apache.catalina.servlets.DefaultServlet.render(DefaultServlet.java:1254)
	at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:951)
	at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:412)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:680)
Comment 1 Daniel Mikusa 2012-09-11 20:50:29 UTC
Created attachment 29357 [details]
Patch to DefaultServlet to workaround the error.

I was able to work around this error with a slight modification to the DefaultServlet code.  Not sure if this is the best solution, but it seems to work without breaking anything so I'm attaching it here.
Comment 2 Mark Thomas 2012-09-17 16:24:36 UTC
The proposed patch fixes the symptom rather than the cause. The fix needs to be in BaseDirContext and other classes in the same package.
Comment 3 Daniel Mikusa 2012-09-18 16:37:57 UTC
Created attachment 29384 [details]
Updated patch, works with BaseDirContext and FileDirContext
Comment 4 Mark Thomas 2012-09-18 17:22:35 UTC
The patch is not functionally correct for FileDirContext and still does not address the root cause.

Issue include:
- ignores WARDirContext
- ignores 3rd party sub-classes
- does not use correct priority for aliases
Comment 5 Mark Thomas 2012-09-30 19:49:17 UTC
This has been fixed in trunk and 7.0.x and will be included in 7.0.31 onwards.