aspose file tools*
The moose likes Tomcat and the fly likes read jndi from outside the container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "read jndi from outside the container" Watch "read jndi from outside the container" New topic
Author

read jndi from outside the container

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

Is it possible to get a connection from the JNDI from outside the container in Tomcat? (From a JUnit integration test in particular.)

I think the answer is no because Apache's FAQ implies you can't do that. I saw this which tells you how to inject your own datasource in what looks like a different JNDI but that's the opposite of what I want to do. I want to use the same connection settings as the actual app.

Or this is a security thing?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

I'd thought about that long ago. I think that (aside from security) the biggest problem is that the JNDI server in Tomcat doesn't have a network port, and therefore isn't accessible from outside the VM.

If the unit tester is actually launching Tomcat, it might be easier to have the pre-test setup write out a context XML file that gets fed to the launched Tomcat. In other words, instead of reading the server's JNDI, set the JNDI data from the test itself.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

It's easier to have the code under test read from a standalone connection than inject it into the jndi. I was looking for a way to externalize the settings from the code by using the developer's tomcat jndi setup. Doesn't sound feasible in Tomcat though
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Jeanne Boyarsky wrote:It's easier to have the code under test read from a standalone connection than inject it into the jndi. I was looking for a way to externalize the settings from the code by using the developer's tomcat jndi setup. Doesn't sound feasible in Tomcat though


I'm presuming that your test framework uses an external running tomcat, then, not launching embedded Tomcat.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

Yes (it is the Jfroum integration tests if that matters)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: read jndi from outside the container