General J2EE: Lookup a resource from a client?
Is it valid to lookup a DataSource or any other non-ejb resource from a java client? When I try to lookup a DataSource from a client, I get a ClassCastException cuz the lookup returns a javax.naming.Reference rather than my DataSource.
- Posted by: Srinivasan Ranganathan
- Posted on: January 16 2005 03:05 EST
- Lookup a resource from a client? by Stephane Vaucher on January 16 2005 04:23 EST
- Datasource not possible by Senthil Rajagopal on January 17 2005 03:46 EST
Is it valid to lookup a DataSource or any other non-ejb resource from a java client?
Yes, but please be more specific (f.e. adding a scenario, an example, or code).
When I try to lookup a DataSource from a client, I get a ClassCastException cuz the lookup returns a javax.naming.Reference rather than my DataSource.- Srini
How are you doing the lookup?
You cannot lookup and use a datasource from a client.
If the datasource is in jndi, why couldn't it be accessible?
Not sure if I am using the right terminology to explain this, but anyways I'll try.
The datasource unlike EJBs, does not implement a remote interface. (Notice the returned object is a javax.naming.Reference rather than DataSource). Hence if you want to lookup datasource, you have to be in the same process.
Hope I am making sense, else let me know, I'll try to explain it differently.
If it is possible to put object in JNDI then it is also possible to retrieve it. Ofcourse, you may need to deal with security , depending upon the Application Server.
If you are using WAS or WSAD5.0 you may need to tweak classpath and some properties file. Let me know, if you may need more details.
Thanks for saying it's possible as I'm in the same situation and need to make it work. What tweaks would be required with classpaths etc ?
javax.naming.Reference actually gives the addresses of ten different locations of the DataSource objects.
If I try to find out the class-name of the those objects it gives the the same name as my DB alias with which I configured. I'm using IBM WAS 5.1.
Also, note that I'm able to do it in WAS 3.5
Thanks for all the help !!!