Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding subcontexts to JNDI read-only Context in Tomcat

Status
Not open for further replies.

sedj

Programmer
Aug 6, 2002
5,610
Hi,

I wish to bind an object to Tomcat's InitialContext under the name "java:/abc" however, at the moment I am getting an error that the "java:" Context is read-only.

Has anybody any ideas ?

This is what I triedso far :
Code:
Context jctx = (Context)ctx.lookup("java:");
// jctx.createSubcontext("abc"); // barfs
// jctx.bind("abc", "def"); // as does this
// jctx.addToEnvironment("abc", "def"); // does not barf, but doesn't seem to do much ...

Cheers

Ben
 
ben,
I'm not sure whether you can use the 'java:' alone. I never tried to bind but here is the call that I usually use when using JNDI(it works all the time):-

public static String sEnvConst = "java:comp/env";
public static String sJDBC = "jdbc/My_App";

//This is how I set up my JDBC dynamically.
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup(sEnvConst);
DataSource ds = (DataSource)envContext.lookup(sJDBC);

hopefully you can improvise it.



~za~
You can't bring back a dead thread!
 
Hi maxpower, thanks for your reply.

Yes, I'm familiar with the JNDI "lookup" methods, but my problem is a little more tricky.

We currently use a JBoss connection pool, but are not happy with it because we find that when used in conjuction with Oracle 9i (esp. shared server 1526 port) the connections often go stale, are not released or experience some other problem. Also there is not much control over the pool dynamically for stopping/starting pools without application restarts, or for logging purposes. So I have written a custom pool using JMX, and have a DataSource implementation which I bind to a JNDI context. However, I need to bind it to the "java:" Context because existing code uses lookups like "java:/poolOne" - but cannot because the Context appears to be read-only ...
 
i am currently preparing for my EJB exam. I finished my JNDI section and if I'm not mistake, you can remove/add the string
ONLY after java:/comp/env. I.e,

DataSource ds = (DataSource)ic.lookup("java:comp/env/jdbc/MyJdbc");

in the DD:-
<entity>
...
<resource-ref>
<res-ref-name>jdbc/MyJdbc</res-ref-name>

Pardon my question, but isn't &quot;java:/poolOne&quot; is not following the EJB 2.0 standard?



~za~
You can't bring back a dead thread!
 
Hi,

I'm not using EJB ... so I'm not really fussed about the EJB spec !!! As for EJB 2.0 - I wish - we're using JBoss 2.2 !!!

It may not be the &quot;done&quot; thing, but when you are migrating an entire companies (10 websites) which all, due to legacy code, tend to connect in different ways (ie some via beans, some via DataSource lookups, some via scriptlets), but all use the &quot;java:/poolName&quot; lookup, I'd rather find some way of binding my custom pool DataSource object to this JNDI name, rather than getting me and all the other developers changing all our code !

Welcome to the real world, rather than specifications and standards compliance !

Good luck with your exam by the way !

Cheers

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top