We have two context defined in server.xml. The code for the two applications is the same.
In a class that implements ServletContextListener we try to use InitialContext but in the second context (docbase=./autobid) tomcat throws an exception:
javax.naming.NameNotFoundException: Name java: is not bound in this Context while in the first application (docbase=./portale) there's no problem.
What is the difference between the two context?
Thanks for the collaboration,
Danilo & Andrea
Here's the stack trace for the exception:
javax.naming.NameNotFoundException: Name java: is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at it.marconimobile.businessapplication.portale.sql.InitializeDbProperties.contextInitialized(InitializeDbProperties.java:89)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3250)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3524)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2189)
at org.apache.catalina.startup.Catalina.start(Catalina.java:510)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
Here's the portion of code:
try {
Context ctx = (Context) new InitialContext().lookup("java:/comp/env"
}
catch (NamingException ex) {
context.log("ERROR"
ex.printStackTrace();
}
Here'a portion of our server.xml file:
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="5" displayName="Application 1" docBase="./portale" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/portale" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Logger className="org.apache.catalina.logger.FileLogger" debug="9" directory="logs" prefix="localhost_portale." suffix=".txt" timestamp="true" verbosity="4"/>
<Resource name="jdbc/conn1" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn2" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn3" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn4" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn5" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/conn1">
...
</ResourceParams>
<ResourceParams name="jdbc/conn2">
...
</ResourceParams>
<ResourceParams name="jdbc/conn3">
...
</ResourceParams>
<ResourceParams name="jdbc/conn4">
...
</ResourceParams>
<ResourceParams name="jdbc/conn5">
...
</ResourceParams>
</Context>
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="5" displayName="Application 2" docBase="./autobid" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/autobid" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Logger className="org.apache.catalina.logger.FileLogger" debug="9" directory="logs" prefix="localhost_autobid." suffix=".txt" timestamp="true" verbosity="4"/>
<Resource name="jdbc/conn1" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn2" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn3" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/conn1">
...
</ResourceParams>
<ResourceParams name="jdbc/conn2">
...
</ResourceParams>
<ResourceParams name="jdbc/conn3">
...
</ResourceParams>
</Context>
In a class that implements ServletContextListener we try to use InitialContext but in the second context (docbase=./autobid) tomcat throws an exception:
javax.naming.NameNotFoundException: Name java: is not bound in this Context while in the first application (docbase=./portale) there's no problem.
What is the difference between the two context?
Thanks for the collaboration,
Danilo & Andrea
Here's the stack trace for the exception:
javax.naming.NameNotFoundException: Name java: is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at it.marconimobile.businessapplication.portale.sql.InitializeDbProperties.contextInitialized(InitializeDbProperties.java:89)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3250)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3524)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2189)
at org.apache.catalina.startup.Catalina.start(Catalina.java:510)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
Here's the portion of code:
try {
Context ctx = (Context) new InitialContext().lookup("java:/comp/env"
}
catch (NamingException ex) {
context.log("ERROR"
ex.printStackTrace();
}
Here'a portion of our server.xml file:
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="5" displayName="Application 1" docBase="./portale" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/portale" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Logger className="org.apache.catalina.logger.FileLogger" debug="9" directory="logs" prefix="localhost_portale." suffix=".txt" timestamp="true" verbosity="4"/>
<Resource name="jdbc/conn1" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn2" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn3" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn4" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn5" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/conn1">
...
</ResourceParams>
<ResourceParams name="jdbc/conn2">
...
</ResourceParams>
<ResourceParams name="jdbc/conn3">
...
</ResourceParams>
<ResourceParams name="jdbc/conn4">
...
</ResourceParams>
<ResourceParams name="jdbc/conn5">
...
</ResourceParams>
</Context>
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="5" displayName="Application 2" docBase="./autobid" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/autobid" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Logger className="org.apache.catalina.logger.FileLogger" debug="9" directory="logs" prefix="localhost_autobid." suffix=".txt" timestamp="true" verbosity="4"/>
<Resource name="jdbc/conn1" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn2" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<Resource name="jdbc/conn3" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/conn1">
...
</ResourceParams>
<ResourceParams name="jdbc/conn2">
...
</ResourceParams>
<ResourceParams name="jdbc/conn3">
...
</ResourceParams>
</Context>