Hi Carsten,
On Thu, 2002-06-06 at 07:31, Carsten Ziegeler wrote:
> Hi David,
>
>
> I don't now the problem, but as far as I can tell, the init-classloader
> param is evaluated. In CocoonServlet, line 306 (current CVS):
> this.addClassDirs = "true".equalsIgnoreCase(value) ||
> "yes".equalsIgnoreCase(value);
>
> and this boolean is used at several places throughout the servlet class.
>
> So, what does your patch change?
>
> Carsten
>
This parameter is evaluated, but it is only used when the servlet is
checking to see if it should "build its own classpath" (something I
don't think it should be doing anyway). Regardless of what the
init-classloader parameter is set to, user-level code will always be
executed with the RepositoryClassLoader, which breaks JNDI in Tomcat.
Take a look at line 936 of CocoonServlet.java (the latest CVS revision):
/* HACK for reducing class loader
problems. */
/* example: xalan extensions fail if someone adds xalan jars in
tomcat3.2.1/lib */
try {
Thread.currentThread().setContextClassLoader(classLoader);
} catch (Exception e){}
The ContextClassLoader is set, regardless of the init-classloader
parameter. My patch (attached) simply adds checks for this parameter,
here and a few other needed places -- although I would like to emphasize
that I think this should be considered a temporary solution, because
(just to reiterate :-), the Java API docs imply that it is a Thread's
creator's responsbility to set the ContextClassLoader (which Tomcat does
appropriatley), and the J2EE spec also states that this is the
container's responsibility (which again would be Tomcat) -- so
certainly, although RepositoryClassLoader is obviously needed for
internal purposes, it should never be there when user-level code is
being executed. But apparently there were/are some very strange class
loading issues that prompted this "HACK"... does anyone know what they
are?
Thanks,
David
Index: CocoonServlet.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
retrieving revision 1.25
diff -u -r1.25 CocoonServlet.java
--- CocoonServlet.java 1 Jun 2002 14:44:42 -0000 1.25
+++ CocoonServlet.java 6 Jun 2002 18:35:04 -0000
@@ -207,9 +207,12 @@
// Force context classloader so that JAXP can work correctly
// (see javax.xml.parsers.FactoryFinder.findClassLoader())
- try {
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- } catch (Exception e){}
+ // Only force if not already set
+ if( Thread.currentThread().getContextClassLoader() == null ) {
+ try {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ } catch (Exception e){}
+ }
String value;
@@ -441,9 +444,11 @@
*/
public void destroy()
{
- try {
- Thread.currentThread().setContextClassLoader(classLoader);
- } catch (Exception e){}
+ if( this.addClassDirs ) {
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ } catch (Exception e){}
+ }
if (this.cocoon != null)
{
@@ -935,9 +940,11 @@
/* HACK for reducing class loader problems. */
/* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
- try {
- Thread.currentThread().setContextClassLoader(classLoader);
- } catch (Exception e){}
+ if( this.addClassDirs ) {
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ } catch (Exception e){}
+ }
// This is more scalable
long start = System.currentTimeMillis();
@@ -1242,9 +1249,11 @@
/* HACK for reducing class loader problems. */
/* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib */
- try {
- Thread.currentThread().setContextClassLoader(this.classLoader);
- } catch (Exception e){}
+ if( this.addClassDirs ) {
+ try {
+ Thread.currentThread().setContextClassLoader(this.classLoader);
+ } catch (Exception e){}
+ }
this.updateEnvironment();
this.forceLoad();
@@ -1289,7 +1298,7 @@
* of this class (eg. Cocoon Context).
*/
protected void updateEnvironment() throws ServletException {
- this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classLoader);
+ this.appContext.put(Constants.CONTEXT_CLASS_LOADER, Thread.currentThread().getContextClassLoader());
this.appContext.put(Constants.CONTEXT_CLASSPATH, getClassPath());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]