You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Worrall <pa...@apcentric.com> on 2003/08/03 22:28:47 UTC

Configuration of Customer Resource Factory in JNDI

I am using Tomcat 4.1.12-LE-jdk14 and am trying to create a resource to
return an org.apache.ojb.broker.PersistenceBroker object from the Apache
OJB 1.0.rc3 distribution using my own implementation of the
javax.naming.spi.ObjectFactory class called FLGPersistentBrokerFactory.
Although Tomcat starts OK and appears to register my factory class when
I come to use it in the web app I get:-
 
JNDI lookup failed : javax.naming.NamingException: Cannot create
resource instance
 

All the details are presented below.  If anyone can help it would be
much appreciated.  I have looked long and hard at all the lists and
documentation and can't resolve the problem.
 
TIA
 
Paul W.
 

My factory class is defined in server.xml as such...
 
  <!-- Global JNDI resources -->
  <GlobalNamingResources>
    <Resource name="bean/FLGPersistenceBrokerFactory"
     auth="Container"
 type="org.apache.ojb.broker.PersistenceBroker"
 description="Global provider of Apache OJB PersistentBroker Objects">
    </Resource>
    <ResourceParams name="bean/FLGPersistenceBrokerFactory">
    <parameter>
     <name>factory</name>
 <value>com.flg.smsport.m.FLGPersistenceBrokerFactory</value>
    </parameter>
    </ResourceParams>
 
  </GlobalNamingResources>
 

My web.xml resources in my web app are defined as so....
 
  <resource-ref>
    <description>Object factory for Apache OJB
PersistenceBroker's</description>
    <res-ref-name>bean/FLGPersistenceBrokerFactory</res-ref-name>
   <res-type>org.apache.ojb.broker.PersistenceBroker</res-type>
    <res-auth>CONTAINER</res-auth>
  </resource-ref>
 

My factory class code is...
 

import java.util.*;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
 
import org.apache.ojb.broker.*;
import org.apache.ojb.broker.query.*;
 

/**
 *
 * @author  worrallp
 */
public class FLGPersistenceBrokerFactory implements
javax.naming.spi.ObjectFactory {
    
    public Object getObjectInstance(Object obj, javax.naming.Name name,
javax.naming.Context context, java.util.Hashtable hashtable)
            throws NamingException {
        
            Object broker = null;
        
                try {
                        System.out.println("Factory object
getObjectInstance method called..");
   broker = (Object)
PersistenceBrokerFactory.defaultPersistenceBroker();
  }
  catch (Throwable t) {
   t.printStackTrace();   
  }
                
                return broker;
        
    }
    
}
 
  
 
I have some test code to inspect the JNDI tree in a servlet and get an
instance of PersistenceBroker....
 

 try {
            Context envCtx = (Context) ctx.lookup("java:comp/env");
            out.println("listBindings() on bean Context : ");
            NamingEnumeration enum = envCtx.listBindings("bean");
            while (enum.hasMoreElements()) {
                out.print("Binding : ");
                out.println(enum.nextElement().toString());
            }
            
            PersistenceBroker broker = (PersistenceBroker)
envCtx.lookup("bean/FLGPersistenceBrokerFactory");
            out.print("Broker from FLGPersistenceBrokerFactory: " +
broker);
            
        } catch (NamingException e) {
            out.println("JNDI lookup failed : " + e);
        } catch( Throwable e) {
            out.print("Something failed." + e);
        }
 

Produces.....
 
listBindings() on bean Context : 
Binding : FLGPersistenceBrokerFactory:
org.apache.naming.ResourceRef:ResourceRef[className=org.apache.ojb.broke
r.PersistenceBroker,factoryClassLocation=null,factoryClassName=org.apach
e.naming.factory.ResourceFactory,{type=description,content=Object
factory for Apache OJB
PersistenceBroker's},{type=scope,content=Shareable},{type=auth,content=C
ONTAINER}]
JNDI lookup failed : javax.naming.NamingException: Cannot create
resource instance