JNDI Lookup to java:comp/env results in 'javax.naming.NameNotFoundException: java:comp/env'
Hi,
we use a third party application which can be enabled to use datasources of the application server for database access.
With JBoss 5.x the application worked fine using datasources which were configured within the JBoss instance.
After migration to JBoss EAP 6.2 EAP the application fails when trying to use a datasource.
The logfile of the application shows then the following entry:
16:50:31,856 INFO [dbRequest] (pool-4-thread-1) isPooled: true
16:50:31,858 ERROR [dbRequest] (pool-4-thread-1) javax.naming.NameNotFoundException: java:comp/env
at org.jboss.as.naming.InitialContext.findContext(InitialContext.java:198)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:118)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler.getConnection(Unknown Source)
at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler.access$100(Unknown Source)
at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler$1.call(Unknown Source)
at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
When decompling the library they use for opening a datasource connection we found the following code:
InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:comp/env");
DataSource dataSource = (DataSource)context.lookup(string5);
logger.info((Object)"CVDBBackendHandler.getConnection() out");
return dataSource.getConnection();
I could veryfy with a simple EAR that the following line causes "NameNotFoundException" in JBoss EAP 6.2 GA and JBoss 6.4 GA:
Context context = (Context)initialContext.lookup("java:comp/env");
We opened a ticket against the vendor, but he insists that the JNDI context "java:comp/env" still exists in 6.2 and 6.4 and rejected the ticket.
The interesting part is, that all RH EAP documentation we found, this JNDI context is still referenced for EAP 6.x.
So here are our questions:
a) if "java:comp/env" is still available, why get I a "NameNotFoundException" when I use 'Context context = (Context)initialContext.lookup("java:comp/env");'?
Do I have to change somethin in the "standalone.xml"?
b) if "java:comp/env" isn't supported any longer, where can I find an official statment, that it isn't any longer?
Best Regards
Peter
Responses
Hi
Take a look at the following Knowledge Base Article [1]. I'm a little confused cos you're not actually looking up the jndi name in the code snippet you've linked. You're just trying to lookup the namespace and not the jndi name of the datasource being deployed. Take a look at https://github.com/jasinner/redhat/blob/master/jndi-datasource/src/main/java/example/TestServlet.java for what I'm referring to.
[1] https://access.redhat.com/solutions/1408753
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
