It does not work because the java:comp/env context is unique to a j2ee component. The
mechanism used to create a unique namespace between j2ee components is the
ClassLoader that was used to deploy the component. When the Cocoon servlet creates
its own ClassLoader it effectively changes its java:comp/env binding to a new one
that has not been created.

You have to install the component ClassLoader as the thread context ClassLoader
any time you lookup the java:comp/env context. Once you have this, you can
use the Cocoon ClassLoader to lookup info from the context.

Context myEnv = null;
ClassLoader cocoonLoader = Thread.currentThread().getContextClassLoader();
ClassLoader deployerLoader = loader.getParent();
try
{
    Thread.currentThread().setContextClassLoader(deployerLoader);
    myEnv = (Context) new IntialContext().lookup("java:comp/env");
}
finally
{
    Thread.currentThread().setContextClassLoader(cocoonLoader);
}

----- Original Message ----- 
From: "Sven Kuenzler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 10, 2001 12:55 AM
Subject: [JBoss-user] EmbeddedTomcat, JNDI and Classloader


> I am trying to deploy the Cocoon 2 XML publishing framework with JBoss
> 2.2.2/Tomcat 3.2.2. This works quite well, except for one issue that I like
> to have explained.
> 
> When trying to lookup an EJB from a Cocoon  XML page ala
> 
>   home = new InitialContext().lookup("java:comp/env/ejb/ContactHome");
> 
> I get an '"env" not bound' exception. I found out that some "classloader
> hack" in the Cocoon Servlet causes this problem.
> 
> In order to support a large variety of servlet containers, Cocoon deploys a
> Classloader of its own. Essentially, it does something like
> 
> cl = Thread.currentThread().getContextClassLoader();
> try{
>    Thread.currentThread().setContextClassLoader(new URLClassLoader({}, cl
> ...)
> 
> ...
> 
> (Actually, it is a subclass of URLClassLoader, but it does not change the
> main behaviour of Sun's implementation).
> When removing this hack from the Cocoon servlet, everything works again.
> So, why is the env context not visible when using a different class loader?
> Please note that this new loader has Tomcat's original AdaptiveClassLoader
> as its parent.
> 
> As I said, I can painlessly remove this "hack" as I don't use  features like
> XSLT extensions. But what would you suggest to someone how needs this class
> loader hack and still wants to do JNDI lookups?
> 
>     Thanks, Sven....
> 
> 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
> 


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to