Re: JNDI lookup returns NamingException
Many thanks to Doug and Seven. The core problem on our Windows machines was that we neglected to put a entry in the ROOT.xml in the Documents and Settings\. directory. On the Linux servers (running 5.5), we needed to put a entry in the Context.xml under META-INF. And, to think we worked for several hours on such a simple problem. Thanks again, Carl - Original Message - From: "Parsons Technical Services" <[EMAIL PROTECTED]> To: "Tomcat Users List" Sent: Tuesday, February 15, 2005 11:16 PM Subject: Re: JNDI lookup returns NamingException > 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" > 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"): > > > > > > > debug="0"/> > > > className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" > > debug="0"/> > > > > > > > > > > > > > > > > > > > type="org.apache.catalina.UserDatabase" > > description="User database that can be updated and saved"> > > > > > > > > > > factory > > org.apache.catalina.users.MemoryUserDatabaseFactory > > > > > > pathname > > conf/tomcat-users.xml > > > > > > > > > > factory > > com.tsr.factory.HashtableFactory > > > > > > > > > > > > > type="java.lang.Integer"/> > > > > > > > > > > > > > port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" > > enableLookups="false" redirectPort="8443" acceptCount="100" > > debug="0" connectionTimeout="2" > > disableUploadTimeout="true" /> > > > enableLookups="false" redirectPort="8443" debug="0" > > protocol="AJP/1.3" /> > > > > > > > > > > > prefix="catalina_log." suffix=".txt" > > timestamp="true"/> > > > > > debug="0" resourceName="UserDatabase"/> > > > > > unpackWARs="true" autoDeploy="true" > > xmlValidation="false" xmlNamespaceAware="false"> > > > > > directory="logs" prefix="localhost_log." suffix=".txt" > > timestamp="true"/> > > > > > > > > > > > > > > > > > > > > > > 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.in
Re: JNDI lookup returns NamingException
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" 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"): factory org.apache.catalina.users.MemoryUserDatabaseFactory pathname conf/tomcat-users.xml factory com.tsr.factory.HashtableFactory 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]
Re: JNDI lookup returns NamingException
Hi, See if having a pair of the sequence of instead of having Resource, Resource ResourceParams, ResourceParams. Also the seems to be misplaced, not that it will much difference for your set-up. aka_sergio --- Carl <[EMAIL PROTECTED]> wrote: > 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"): > > > className="org.apache.catalina.mbeans.ServerLifecycleListener" > debug="0"/> > className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" > debug="0"/> > > > > > > type="java.lang.Integer" value="30"/> > > > type="org.apache.catalina.UserDatabase" > description="User database that can be updated and > saved"> > > type="java.util.Hashtable"/> > > > factory > org.apache.catalina.users.MemoryUserDatabaseFactory > > > pathname > conf/tomcat-users.xml > > > > > factory > com.tsr.factory.HashtableFactory > > > > > > global="simpleValue" > type="java.lang.Integer"/> > > > > > > port="8080" maxThreads="150" minSpareThreads="25" > maxSpareThreads="75" > enableLookups="false" redirectPort="8443" > acceptCount="100" > debug="0" connectionTimeout="2" > disableUploadTimeout="true" /> > enableLookups="false" redirectPort="8443" debug="0" > protocol="AJP/1.3" /> > > debug="0"> > > > className="org.apache.catalina.logger.FileLogger" > prefix="catalina_log." suffix=".txt" > timestamp="true"/> > > className="org.apache.catalina.realm.UserDatabaseRealm" > debug="0" resourceName="UserDatabase"/> > > unpackWARs="true" autoDeploy="true" > xmlValidation="false" xmlNamespaceAware="false"> > > className="org.apache.catalina.logger.FileLogger" > directory="logs" prefix="localhost_log." > suffix=".txt" > timestamp="true"/> > > > > > > > > > > > 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) > === message truncated ===
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"): factory org.apache.catalina.users.MemoryUserDatabaseFactory pathname conf/tomcat-users.xml factory com.tsr.factory.HashtableFactory 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]