I've implemented my own DirContext, which extends FileDirContext, and allows one to 
specify any number of directories on the webapp's classpath.  The solution works 
wonderfully, once I hacked around what I think are bugs in Tomcat.  

It seems that when you specify your own <Resources> entry for a <Context>, Tomcat does 
things in slightly the wrong order during initialization.  I have the following 
structure in my server.xml:

<Host ...>
  <Context ... >
    <Resources className="com.my.dirContext" ... />
  </Context>
</Host>

During the parsing of the server.xml file, setResources() is called on the 
StandardContext object, passing in an instance of my custom DirContext object.  At 
this point, Tomcat creates a ProxyDirContext, wrapping my custom DirContext.  During 
the initialization of the ProxyDirContext, the host is not properly determined and set 
in the environment.  As far as I can tell, this is because at this point in the 
initialization, the <Context> entry has not had its parent set yet.

This causes all kinds of problems later, since the ProxyDirContext will improperly 
determine the path to resources if it doesn't have a valid entry for "host" in its 
environment.  I'm using TC 4.0.6, and have gotten around this by hacking 
StandardContext.getBasePath() and ContainerBase.setParent().

Has anyone else seen this problem?  Is it fixed in a later version?

Dave

-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 22, 2003 5:30 PM
To: Tomcat Users List
Subject: RE: Resources for a Context




On Wed, 22 Jan 2003, David Keyes wrote:

> Date: Wed, 22 Jan 2003 17:09:44 -0500
> From: David Keyes <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: RE: Resources for a Context
>
> I would be happy to make any modifications that would be required.  I've spent a bit 
>of time looking around at the source already, but I'm not sure what the best approach 
>would be.  It would be nice if it could be done in a "plugin" kind of way, but after 
>looking around a bit, it seems that the concept of a single physical directory as a 
>docbase is pretty ingrained (comments?).
>
> So far, I've looked at the following:
>
> 1. Writing a new catalina Context implementation
> 2. Writing a new jndi DirContext implementation, that would be configurable to take 
>multiple directories
>
> Of those two, I think #2 makes the most sense, but I have doubts as to
> whether it would solve the problem.  What I'm afraid of is that the
> changes required are peppered throughout the Tomcat codebase.  Any
> pointers that you could give me to get me started in the right direction
> initially would be hugely appreciated.
>

#2 makes sense to me.  Basing your class on the existing code in
FileDirContext (in particular, you'll probably want to subclass
BaseContext), but allowing it to be configured with multiple directories,
should keep you very insulated from the rest of the Tomcat internals.
The rest of Tomcat just works through DirContext.

You'll have to decide what to do when there's more than one of the
directories that have a file or subdirectory of the same name -- perhaps
in the order that the directories are configured.

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to