You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Torgeir Veimo <to...@vertech.no> on 2001/04/03 12:04:57 UTC

context factories

I've read in a post by Remy with subject: "Re: <ejb-ref> <ejb-link>
Implementation in 4.0.b1",
http://w4.metronet.com/~wjm/tomcat/2001/Mar/msg00273.html that the only
two factories supported in tomcat right now is one for getting Tyrex
managed data sources & User Transactions.

I'm interested in getting a resource factory that I've created myself to
reuse jndi context's to an LDAP database that is used for authentication
& more.

I've created a ContextPool that handles this, and I want to retrieve
this with initCtx.lookup("java:comp/env/jndi/ContextPool");

How do I create and add the necessary resource factory? Should I modify
org.apache.naming.factroy.ResourceFactory.java ?

Any hints appreciated.


-- 
- Torgeir

Re: context factories

Posted by Torgeir Veimo <to...@vertech.no>.
Btw, if I replace the instanceof test with a 

getClass().getName().equals("org.apache.naming.ResourceRef") 

it all works. 

-- 
- Torgeir

Re: context factories

Posted by Torgeir Veimo <to...@vertech.no>.
"Craig R. McClanahan" wrote:
> 
> If you don't mind specifying the resource factory class yourself, you
> don't need to modify any code at all -- just configure it in server.xml
> like this:
> 
>   <Context path="/myapp" ... >
>     ...
>     <Resource name="jndi/ContextPool"
>               type="com.mycompany.ContextPool"/>
>     <ResouceParams name="jndi/ContextPool">
>       <parameter>
>         <name>factory</name>
>         <value>com.mycompany.ContextPoolFactory</value>
>       </parameter>
>       <parameter><name>name</name><value>value</value></parameter>
>       ...
>     </ResourceParams>
>     ...
>   </Context>
> 
> where "com.mycompany.ContextPoolFactory" is a class that implements
> javax.naming.spi.ObjectFactory.  You can use the existing factories as
> examples of how such factories can access the declared resource parameters
> and use them to configure the object itself.

Ok, I've configured this, and all I get back from the initCtx.lookup()
method is a ResourceRef, not a ContextPool. 

I have found the reason for this to be that the "instanceof" check in
the getObjectInstance() method in
org.apache.naming.factory.ResourceFactory fails, and this must be due to
classloader issues.

What are the magic spells I need to cast to get classloading right? 

Can I put the ContextPoolFactory in an independent jar file in lib,
common/lib or server/lib?


-- 
- Torgeir

Re: context factories

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 3 Apr 2001, Torgeir Veimo wrote:

> I've read in a post by Remy with subject: "Re: <ejb-ref> <ejb-link>
> Implementation in 4.0.b1",
> http://w4.metronet.com/~wjm/tomcat/2001/Mar/msg00273.html that the only
> two factories supported in tomcat right now is one for getting Tyrex
> managed data sources & User Transactions.
> 

This message is actually out of date now.  There are also default
factories to create javax.mail.Session and
javax.mail.internet.MimePartDataSource as well.

> I'm interested in getting a resource factory that I've created myself to
> reuse jndi context's to an LDAP database that is used for authentication
> & more.
> 
> I've created a ContextPool that handles this, and I want to retrieve
> this with initCtx.lookup("java:comp/env/jndi/ContextPool");
> 
> How do I create and add the necessary resource factory? Should I modify
> org.apache.naming.factroy.ResourceFactory.java ?
> 

If you don't mind specifying the resource factory class yourself, you
don't need to modify any code at all -- just configure it in server.xml
like this:

  <Context path="/myapp" ... >
    ...
    <Resource name="jndi/ContextPool"
              type="com.mycompany.ContextPool"/>
    <ResouceParams name="jndi/ContextPool">
      <parameter>
        <name>factory</name>
        <value>com.mycompany.ContextPoolFactory</value>
      </parameter>
      <parameter><name>name</name><value>value</value></parameter>
      ...
    </ResourceParams>
    ...
  </Context>

where "com.mycompany.ContextPoolFactory" is a class that implements
javax.naming.spi.ObjectFactory.  You can use the existing factories as
examples of how such factories can access the declared resource parameters
and use them to configure the object itself.

> Any hints appreciated.
> 
> 
> -- 
> - Torgeir
> 

Craig McClanahan