Bug 38131 - WatchedResource does not work if app is outside "webapps"
Summary: WatchedResource does not work if app is outside "webapps"
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.5.12
Hardware: All other
: P2 enhancement with 2 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-05 09:55 UTC by Gernot
Modified: 2008-01-21 03:37 UTC (History)
0 users



Attachments
patch that fixes HostConfig to comply with the documentation regarding docBase and watched resources (3.47 KB, patch)
2007-11-05 23:05 UTC, Peter Lynch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gernot 2006-01-05 09:55:01 UTC
My webapp is placed outside CATALINA_BASE/webapps.
I put my context.xml into CATALINA_BASE/conf/Catalina/localhost.
My context.xml looks like:
<Context docBase="/somedir/mywebapp">
   <WatchedResource>WEB-INF/web.xml</WatchedResource>
   ...some other stuff...
</Context>

If I change web.xml my webapp will not be reloaded!
If insert an absolute path
<WatchedResource>/somedir/mywebapp/WEB-INF/web.xml</WatchedResource>
it works, but to use absolute paths will become unhandy - especially when I try
to put the WatchedResource stuff to defaultcontext.xml, because I have a lot of
webapps not only one.

If I put my webapp in CATALINA_BASE/webapps all works fine - but this is not a
solution for me.
Comment 1 Yoav Shapira 2006-12-24 17:48:52 UTC
First, I'm changing this to an enhancement, as the current code is clearly
designed for absolute paths so what you're reporting is not a bug.

Second, the relevant code you want to look at is in
org.apache.catalina.startup.HostConfig, the addWatchedResourced method.  That
method will loop over the declared WatchedResources for the Context and try to
create a java.io.File corresponding to each WatchedResource for monitoring.  As
you can see from the code, it either wants an absolute path to the
WatchedResource, or a docBase relative to which the WatchedResource can be found.

I'm guessing in your case the docBase is relative, not absolute, so the method
uses appBase as the context for docBase, and since your webapp is outside
appBase this doesn't work.  Is my guess right?  Does it work if you make your
docBase absolute?
Comment 2 Gernot 2006-12-26 23:47:42 UTC
(In reply to comment #1)
> First, I'm changing this to an enhancement, as the current code is clearly
> designed for absolute paths so what you're reporting is not a bug.

I get my infos from documentation and not from the source - and in the docs I
havn't found any info that you need absolute paths.
 
> ... 
> I'm guessing in your case the docBase is relative, not absolute, so the method
> uses appBase as the context for docBase, and since your webapp is outside
> appBase this doesn't work.  Is my guess right?  Does it work if you make your
> docBase absolute?

My docBase is absolute like 
  <Context docBase="${somedir}/appdir">
and ${somedir} is absolute like "c:/webapps".
And it doesn't work with
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
in conf/context.xml,
and it also doesn_t work with
 <WatchedResource>c:/webapps/appdir/WEB-INF/web.xml</WatchedResource>
in conf/context.xml.
Comment 3 Peter Lynch 2007-07-03 08:34:09 UTC
In my tests using tomcat 6.0.13, JDK 1.6, when the path in the WatchedResource
is relative path, the absolute path interpreted by the code as written for the
relative path will be an absolute path to relative to the JVM startup directory.
Obviously something is very quirky in there. Since the path will then most
likely point to an invalid resource, it will not be watched and there is no
warning give to the user either. In this case addWatchedResource is given a
'null' docBase.

The code in question is in HostConfig.deployDescriptor().

Suggested code improvements:
o for descriptors that explicitly specify an absolute docBase, pass it to the
addWatchedResource method instead of 'null'
o print warning if watched resource evaluated path points to a resource that
does not exist

I came up with a fix but I was discouraged to not find any existing unit tests
to verify regression. If there are any please tell me so I can verify the patch.
Comment 4 John Kew 2007-10-24 15:28:42 UTC
I would like to experiment with this patch. Do you think you can post it here
for others to review and test?
Comment 5 Peter Lynch 2007-11-05 23:05:02 UTC
Created attachment 21090 [details]
patch that fixes HostConfig to comply with the documentation regarding docBase and watched resources

I manufactured this patch against the official
org/apache/catalina/startup/HostConfig.java file included with Tomcat 6.0.13.
it is small enough such that recreating it to work with 5.5.x series releases
should be trivial. Hope it helps.You may need to modify the patch header to
apply it.
Comment 6 Peter Rossbach 2008-01-20 06:06:25 UTC
Thanks for patch,

Look at http://svn.apache.org/viewvc?rev=613558&view=rev.

I hope we can at the fix to next tomcat 6/55 release

Peter
Comment 7 Peter Lynch 2008-01-20 18:21:43 UTC
Thanks for applying it.

I am not sure pero wants credit for the patch. I was the one who submitted the
patch but the changes to the changelog seem to indicate that pero provided it.

Changelog reads "Patch provided by Gernot Pfingstl (pero)"

If the patch is applied, should the status stay 'NEW'
Comment 8 Peter Rossbach 2008-01-21 00:43:46 UTC
Fix added for Release 5.5.26 and 6.0.16!
Comment 9 Peter Rossbach 2008-01-21 03:37:08 UTC
I correct my mistake!
Sorry Peter