tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondra Nekola <on...@twin.jikos.cz>
Subject Tomcat JNDI - mapping a String
Date Mon, 23 Feb 2004 10:12:51 GMT
I have developed a small web-based aplication. I use an ant build script 
to compile it and to generate a war. The application is used in several 
servers with different settings (it uses different databases, connects to 
different xml-rpc resources...) so it has to somehow read the 
configuration from the server environment. 
I have used the tomcat Web server administration tool to set Resources - a 
data source and several Environment Entries. The tool regenerates 
server.xml file in such a manner:

<Server>
...
  <GlobalNamingResources>
    <Environment description="" name="BLAH_USER" type="java.lang.String" 
value="MrSpock"/>
...
  </GlobalNamingResources>
...
</Srver>

Then I change my deployment descriptor get access to this environment:
<web-app>
...
  <resource-env-ref>
    <resource-env-ref-name>BLAh_USER</resource-env-ref-name>
    <resource-env-ref-type>java.lang.String</resource-env-ref-type>
  </resource-env-ref>
...
</web-app>

The code, that tryes to read this environmnt looks like this:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
String res_user = (String) envCtx.lookup("BLAH_USER");

The problem is, that I get this exception:
javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:146)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:837)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:197)
        at myapp.servlets.MyAppListener.contextInitialized(MyAppListener.java:123)

When I try to access a mapped JDBC resource everything seems to be OK. 
When I list (NamingEnumeration enum = initCtx.list("java:comp/env");) the 
keys for mapped resources BLAH_USER appears.

I have tried look this situation in the Tomcat documentation and to google 
it, but I haven't get any reasonable idea to solve it.
-- 
   S pozdravem
       Ondrej Nekola
       ondra@matfyz.cz
       http://www.matfyz.cz/ondra
       ICQ# 160692888

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message