RE: Access Tomcat-declared Resource from outside Tomcat

2003-10-21 Thread Shapira, Yoav

Howdy,
Currently tomcat doesn't have an external JNDI provider, so you can't
really do what you're looking for.

Yoav Shapira
Millennium ChemInformatics


-Original Message-
From: Ian Hunter [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 21, 2003 10:50 AM
To: [EMAIL PROTECTED]
Subject: Access Tomcat-declared Resource from outside Tomcat

I've got a database resource declared as part of Tomcat's resource pool
(JNDI?) -- I need a standalone Java app to access it.  How do I declare
such
a thing in a standalone app?

I realize this is slightly off topic but I figured someone else out
there
might try to do the same thing.

Literally, what I'm doing is creating an alert subsystem that at
certain
times, the OS schedules a batch run, and it queries for certain
conditions
occurring in database tables, and emails people alerts.

Thanks all!

Ian


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Access Tomcat-declared Resource from outside Tomcat

2003-10-21 Thread Ian Hunter
I don't follow you -- shouldn't I be able to create an instance of a naming
context and populate it from within my App, then refer back to it?  For this
app, I don't mind hard coding the parameters, it's just that I have a class
called DataStore that contains all the access points to the persistence
layer of my web app.  The DataStore class knows nothing about Tomcat.

Surely I can use some other JNDI provider and fool the DataStore class
into talking to it... In fact, here is the single point of reference to the
database resource:

// Return DataSource via JNDI with object named in
Constants.DATABASE_KEY
public static javax.sql.DataSource getDs() throws java.sql.SQLException
{
javax.sql.DataSource ds = null;

try {
// Obtain our environment naming context
javax.naming.Context initCtx = new
javax.naming.InitialContext();
javax.naming.Context envCtx = (javax.naming.Context)
initCtx.lookup(java:comp/env);

// Look up our data source
String check = Constants.DATABASE_KEY;
ds = (javax.sql.DataSource)
envCtx.lookup(Constants.DATABASE_KEY);
} catch (javax.naming.NamingException e) {
e.printStackTrace();
return null;
}
return ds;
}

What else can I use as a JNDI provider?
- Original Message - 
From: Shapira, Yoav [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Tuesday, October 21, 2003 11:01 AM
Subject: RE: Access Tomcat-declared Resource from outside Tomcat



Howdy,
Currently tomcat doesn't have an external JNDI provider, so you can't
really do what you're looking for.

Yoav Shapira
Millennium ChemInformatics


-Original Message-
From: Ian Hunter [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 21, 2003 10:50 AM
To: [EMAIL PROTECTED]
Subject: Access Tomcat-declared Resource from outside Tomcat

I've got a database resource declared as part of Tomcat's resource pool
(JNDI?) -- I need a standalone Java app to access it.  How do I declare
such
a thing in a standalone app?

I realize this is slightly off topic but I figured someone else out
there
might try to do the same thing.

Literally, what I'm doing is creating an alert subsystem that at
certain
times, the OS schedules a batch run, and it queries for certain
conditions
occurring in database tables, and emails people alerts.

Thanks all!

Ian


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Access Tomcat-declared Resource from outside Tomcat

2003-10-21 Thread Shapira, Yoav

Howdy,

I don't follow you -- shouldn't I be able to create an instance of a
naming
context and populate it from within my App, then refer back to it?  For

No.  You need a JNDI provider to do this.  There is a lot going on in
the background when you create naming context and bind into them.

javax.sql.DataSource ds = null;

try {
// Obtain our environment naming context
javax.naming.Context initCtx = new
javax.naming.InitialContext();

This uses the default initial context factory, which is not tomcat.  To
use tomcat's initial context factory, you need to configure the initial
context above, e.g.
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
org.apache.naming.java.javaURLContextFactory);
ht.put(Context.PROVIDER_URL, http://mytomcatserver);
Context initCtx = new InitialContext(ht);

If you're not clear on the difference between your code (the default
initial context constructor) and the above, read up on JNDI.

The tomcat initial context factory implementation (the class named
above) is here:
http://cvs.apache.org/viewcvs/jakarta-tomcat-catalina/catalina/src/share
/org/apache/naming/java/

Now, if you tried the above, and had a tomcat server running, and had
the naming jar in your classpath (so your app does need to know about
tomcat, however implicitly, via classpath and class name above), it
STILL wouldn't work.  That's because tomcat doesn't support external
JNDI calls.

What else can I use as a JNDI provider?

Any full-featured J2EE server (e.g. JBoss), and some specific
non-full-J2EE servers that support external JNDI, e.g. OpenJMS.

Or you could enhance tomcat to support external JNDI ;)

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]