Bug 51741 - Eclipse WTP "Serve modules without publishing" broken with tc7, needs patch in tomcat
Summary: Eclipse WTP "Serve modules without publishing" broken with tc7, needs patch i...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.20
Hardware: Macintosh All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-29 21:29 UTC by Sylvain Laurent
Modified: 2014-02-17 13:43 UTC (History)
3 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Laurent 2011-08-29 21:29:56 UTC
Eclipse WTP has an option "Serve modules without publishing" that works well with tc6, but not with tc7.
After investigation by the WTP team, there seem to be no way for them to fix this without modifying tomcat. The problem in WTP is reported here : https://bugs.eclipse.org/bugs/show_bug.cgi?id=333102

Basically, their DirContext implementation (org.eclipse.jst.server.tomcat.loader.WtpDirContext) returns a ResourceAttributes that correctly points to an existing location, but org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String) ignores it and returns a ResourceEntry whose codeBase and source fields point to a non-existing location.
This breaks applications that call getResource(...) on the Thread ContextClassLoader and use the returned URL.
A call to getResourceAsStream(...) on the Thread CCL is OK.
Comment 1 Sylvain Laurent 2011-08-29 21:32:41 UTC
I'm preparing a patch for org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String) but I'm also wondering if tomcat should not provide such a "virtual" DirContext just like org.apache.catalina.loader.VirtualWebappLoader is provided (which could probably be used by WTP instead of org.eclipse.jst.server.tomcat.loader.WtpWebappLoader)
Comment 2 Mark Thomas 2011-08-29 22:16:42 UTC
With aliases and altDirContexts this code is already pretty messy. A virtual DirContext may make things worse.
Comment 3 Sylvain Laurent 2011-08-31 20:41:55 UTC
fixed WebappClassLoader in r1163802, will be available in tomcat 7.0.22
Comment 4 Mathieu Ouellet 2011-10-04 16:50:37 UTC
Not sure about the expected behavior of the WepappClassLoader, but here's something I ran into while testing the new release 7.0.22.

I'm still experiencing the issue when using org.apache.catalina.loader.WebappClassLoader.findResources(String).

Unlike org.apache.catalina.loader.WebappClassLoader.findResource(String), it doesn't look for resources into the local repository using org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String), where the fix to this bug can be found.

Not sure if this is an expected behavior, but this use case doesn't seem to be covered by the fix.
Comment 5 Sylvain Laurent 2011-10-04 19:11:46 UTC
you're correct, my fix is not sufficient, I'll work on it soon.
Unfortunately the code in tomcat is quite complex and feels like it has a lot of history, I have to be very careful not to break anything...
Comment 6 Mathieu Ouellet 2011-10-04 19:52:40 UTC
Thank you very much !
Comment 7 Larry Isaacs 2011-10-05 21:06:41 UTC
Sylvain,

Thanks for your work on this.  I've verified the "<classloader>.getResource()" is fixed in Tomcat 7.0.22 for "Serve modules without publishing".  Unfortunately, the testing revealed I missed a change to DirContextURLConnection in 7.0.21 which breaks annotation processing for 3.0 webapps.  See Eclipse bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=360012

This means that WTP 3.2.5, 3.3.2, or 3.4 will be needed to avoid the annotation problem in a released WTP.  An updated org.eclipse.jst.server.tomcat.runtime.70.loader.jar is available in the bug above which fixes the problem.  Until those releases are available, the simplest way to work around if you are using a 3.0 webapp is to edit the org.eclipse.jst.server.tomcat.core plug-in jar to replace the ".70.loader" jar with the updated one.

Finally, I've updated the project set I use for testing to include a test for "<classloader>.getResources()".  I'll try to clean it up some and attach a zip to the Eclipse bug in case you or someone else wants to use it.

Cheers,
Larry
Comment 8 Sylvain Laurent 2011-10-13 18:32:50 UTC
I'm still working on a patch...
Actually, I think that it's really impossible to have a custom DirContext that fakes WEB-INF/classes to allow multiple virtual paths because one way or another it would return inexistent URLs.

So, I started to work on a patch that would allow to specify additional paths that should be searched for annotated classes just like WEB-INF/classes. Such a configuration parameter is located on the StandardContext.

With this patch, WTP could totally avoid to provide its own extensions to tomcat classes and just configure a <Context> with the new property, a <Resource> with the org.apache.naming.resources.VirtualDirContext implementation and a <Loader> with the org.apache.catalina.loader.VirtualWebappLoader implementation.
Comment 9 Larry Isaacs 2011-11-21 13:26:20 UTC
I agree to release under the Apache Licence my changes to WtpDirContext found in the Eclipse WTP source.  These changes extended the source that Fabrizio Giustina originally contributed to both Eclipse and Tomcat.
Comment 10 Sylvain Laurent 2011-12-02 22:41:25 UTC
patch commited on trunk : 1209686 + 1209694 + 1209731

I'll apply to tc 7 in a couple of days
Comment 11 Sylvain Laurent 2011-12-06 21:07:07 UTC
applied on tc7, will be available in 7.0.24.
Comment 12 Mark Thomas 2012-02-15 19:59:18 UTC
Note that the patch to ContextConfig contained invalid assumptions that triggered regressions (see bug 52669). Namely:
- the patch assumed that web applications were always deployed in exploded form
- the patch assumed that classes were always located in packages

The patch also broke OSGi embedded usage.
Comment 13 Konstantin Kolinko 2012-03-30 20:51:25 UTC
See r1307600 for one more issue with the patch.
The fix will be in 7.0.27.