Did you put ResourceLinks in your Default context or the Apps context?
If not, you will not be able to see the resource.
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/globalresources.html
And the link that is in your server.xml shouldn't be there or anywhere. See above link.
Doug
----- Original Message ----- From: "Carl" <[EMAIL PROTECTED]>
To: "Tomcat User Group" <[email protected]>
Sent: Tuesday, February 15, 2005 4:41 PM
Subject: JNDI lookup returns NamingException
For various reasons, I need to put a Hashtable as a resource in the Tomcat
Context. I have modified the server.xml as follows (note the resource entry
of "DBHashtable"):
<Server port="8005" shutdown="SHUTDOWN" debug="0"> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" debug="0"/>
<!-- Global JNDI resources --> <GlobalNamingResources>
<!-- Test entry for demonstration purposes --> <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"> </Resource> <Resource name="DBHashtable" auth="Container" type="java.util.Hashtable"/> <ResourceParams name="UserDatabase"> <parameter> <name>factory</name> <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value> </parameter> <parameter> <name>pathname</name> <value>conf/tomcat-users.xml</value> </parameter> </ResourceParams> <ResourceParams name="DBHashtable"> <parameter> <name>factory</name> <value>com.tsr.factory.HashtableFactory</value> </parameter> </ResourceParams>
</GlobalNamingResources>
<ResourceLink name="linkToGlobal" global="simpleValue" type="java.lang.Integer"/>
<!-- Define the Tomcat Stand-Alone Service --> <Service name="Catalina">
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on the port specified during installation --> <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" /> <Connector port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" /> <!-- Define the top level container in our container hierarchy --> <Engine name="Catalina" defaultHost="localhost" debug="0">
<!-- Global logger unless overridden at lower levels --> <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" debug="0" resourceName="UserDatabase"/>
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/>
</Host>
</Engine>
</Service>
</Server>
My application accesses this resource (well, tries to) using the following code:
try { Context ctx = new InitialContext(); if(ctx == null ){ System.out.println("Boom - No Context"); throw new NamingException("No Context - No DataBase Exists"); }
Context envCtx = (Context)ctx.lookup("java:comp/env"); Object ud = (Object)envCtx.lookup("DBHashtable"); }catch (NamingException ne){ ne.printStackTrace(); // throw new SQLException("Datasource Not Found"); }
It fails of the line "Object ud = (Object)envCtx.lookup("DBHashtable");" with the following error:
javax.naming.NamingException: Cannot create resource instance
at
org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFa
ctory.java:99)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
at org.apache.naming.NamingContext.lookup(NamingContext.java:791)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at LoginServlet.doPost(LoginServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:157)
at com.tsr.filters.RequestFilter.doFilter(RequestFilter.java:78)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:186)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContext
Valve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137
)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117
)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
t.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:683)
at java.lang.Thread.run(Thread.java:534)
I know the factory is OK because I put a println in it and it seems to work
(it only creates a Hashtable.)
Does anyone have an idea of what I have done wrong?
Thanks,
Carl Kabbe
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.8 - Release Date: 2/14/2005
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
