This is the web.xml entry:always perform such a lookup successfully, but when I try from a
ContextListener contextInitialized method it fails: the same code WILL
NOT FAIL contextDestroyed !!!
Hmmm, odd. This is *exactly* what I do pretty much. I have a LifeCycleListener specified in the webapps/<app>/WEB-INF/web.xml like this:
<listener> <listener-class><my.foo.bar.package>.LifeCycleListener</listener-class> </listener>
and then in the contextInitialized method of the LifeCycleListener I do a bunch of calls to jndiContext.lookup().
Hmm, hmmm, hmmm. You are correctly specifying the listener in web.xml?
<listener>
<listener-class>it.masterhouse.termopoli.web.startup.Init</listener-class>
</listener>
<resource-ref> <description> JNDI resource reference to a factory for java.sql.Connection instances that may be used for talking to Babele database (configured in the server.xml file). </description> <res-ref-name> jdbc/Babele </res-ref-name> <res-type> javax.sql.Datasource </res-type> <res-auth> Container </res-auth> </resource-ref>
and this is the context:
<Context path="/termopoli" docBase="termopoli" debug="0" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_termopoli_log." suffix=".txt" timestamp="true"/>
<!-- Pool JNDI per DB2/Babele -->
<Resource name="jdbc/Babele" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/Babele">
<parameter>
<name>username</name>
<value>foo</value>
</parameter>
<parameter>
<name>password</name>
<value>foo</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.ibm.db2.jcc.DB2Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:db2://foo:9999/BABELE</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>8</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>4</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter> </ResourceParams>
</Context>
I can list the JNDI datasource like this:
INFO : [06/06/2003 11:56:50]: it.masterhouse.termopoli.web.startup.Init.printBindings(Init.java:86): Babele: ResourceRef[className=javax.sql.Datasource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory
.ResourceFactory,{type=description,content=JNDI resource reference to a factory for java.sql.Connection
instances that may be used for talking to Babele
database (configured in the server.xml file).},{type=scope,content=Shareable},{type=auth,content=Conta
iner}]
INFO : [06/06/2003 11:56:50]: it.masterhouse.termopoli.web.startup.Init.printBindings(Init.java:88): context j
ava:comp/env/jdbc enumerated
but then:
FATAL: [06/06/2003 11:56:50]: it.masterhouse.termopoli.web.startup.Init.contextInitialized(Init.java:55): Nami
ngException during lookup
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:189)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
at org.apache.naming.NamingContext.lookup(NamingContext.java:834)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at it.masterhouse.termopoli.web.startup.Init.contextInitialized(Init.java:37)
I think the problem is that I cannot get the ResourceParameters: look at a succesfull call:
INFO : [06/06/2003 14:38:31]: it.masterhouse.termopoli.web.startup.Init.printBindings(Init.java:86): Babele: R
esourceRef[className=javax.sql.DataSource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory
.ResourceFactory,{type=scope,content=Shareable},{type=auth,content=Container},{type=url,content=jdbc:db2://foo:9999/BABELE},
{type=maxIdle,content=4},{type=maxActive,content=8},{type=driverClassName,content=c
om.ibm.db2.jcc.DB2Driver},{type=removeAbandoned,content=true},{type=username,content=foo},{type=logAbando
ned,content=true},{type=removeAbandonedTimeout,content=60},{type=password,content=foo}]
INFO : [06/06/2003 14:38:31]: it.masterhouse.termopoli.web.startup.Init.printBindings(Init.java:88): context j
ava:comp/env/jdbc enumerated
INFO : [06/06/2003 14:38:31]: it.masterhouse.termopoli.web.startup.Init.contextInitialized(Init.java:40): attr
ibute datasource set for context [EMAIL PROTECTED]
This is in accordance with the fact that when I tried to deploy the application from webapps putting termopoli.xml and termopoli.war in CATALINA_HOME\webapps, server.xml was modified to include the <Resource> tag but the <ResourceParams> where left out:
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="0" displayName="Termopoli" docBase="C:\java\jakarta-tomcat-4.1.24\webapps\termopoli" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/termopoli" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Resource auth="Container" description="JNDI resource reference to a factory for java.sql.Connection
instances that may be used for talking to Babele
database (configured in the server.xml file)." name="jdbc/Babele" scope="Shareable" type="javax.sql.Datasource"/>
</Context>
I'm surely missing some point ...
Thank you very much, Federico
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]