Jan Luehe's Blog
Alternate Docroots and Local Resource Paths
Alternate Docroots and Local Resource Paths
Judging from the traffic on the various GlassFish mailing lists and user forums, it seems that support for alternate docroots in GlassFish has become very popular.However, from the feedback given, it looks like the way alternate docroot paths are computed by the web container deserves additional coverage: Several developers have tried leveraging alternate docroots and were left wondering why the container would return a 404 response instead of the contents of the requested resource.
Hopefully, this blog will clarify things.
When configuring an alternate docroot, try keeping in mind the following rules:
- Alternate docroots (more specifically, their "from" values) are matched against a request's path info (obtained by calling
javax.servlet.http.HttpServletRequest.getPathInfo()). - The local path of a resource whose request has been matched by an alternate docroot is computed by appending the request's path info to the alternate docroot's "dir" value.
As an example, consider the following alternate docroot declaration in sun-web.xml:
<property name="alternatedocroot_1" value="from=/orderstore/* dir=C:/stryker_cci/orderstore"/>
and this request URL:
http://localhost:8080/CIWeb/orderstore/test.txt
Assume the request is mapped to a web application deployed at /CIWeb, meaning the request URL's context
root component is given as /CIWeb, and its path info component is given as /orderstore/test.txt, which is matched by the above alternate docroot. The local filesystem path where the requested resource will be looked up is given as the value of the alternate docroot's "dir" value:
C:/stryker_cci/orderstore
with the request's path info:
/orderstore/test.txt
appended to it, resulting in:
C:/stryker_cci/orderstore/orderstore/test.txt
As another example, consider the following alternate docroot declaration in sun-web.xml:
<property name="alternatedocroot_1" value="from=/myimages/* dir=/images"/>
and this request URL:
http://localhost:8080/myimages/image1.jpg
Further assume that the above request is mapped to a web application deployed at the root context ("/"). In this case, the request's path info evaluates to:
/myimages/image1.jpg
meaning it is matched by the above alternate docroot. The local filesystem path where the requested resource will be
looked up is given as the value of the alternate docroot's "dir" value:
/images
with the request's path info:
/myimages/image1.jpg
appended to it, resulting in:
/images/myimages/image1.jpg
Posted at 03:05PM Feb 12, 2008 by Jan Luehe in Sun | Comments[2]
Great Luehe. Now is clear and will avoid confusion and headache.
Andre
Posted by Andre on February 12, 2008 at 03:25 PM PST #
Luehe,
I had also posted on your previous blog on this topic.
Given your example, I have an application deployed at /opt/pc/docs/www with a context path of "/".
I then added a new property (alternatedocroot_1) with the value "from=/config/* dir=/opt/pc/docs"
I have other files (DBFrames.dbml) in /opt/pc/docs/config I am trying to reach.
When I enter the URL "http://localhost:8080/config/DBFrames.dbml"
I get the dreaded "404 - config/DBFrames.dbml Not Found"
What am I missing?
Posted by David Dreggors on February 12, 2008 at 08:04 PM PST #