Hi, I'm completely to the Service Locator Pattern. I'm aware of the need. Now, I need to know what is the String to be passed to call the method getDataSource(String datasourceName) of the Service Locator class.
Typically you'd pass in the JNDI name, but you could enhance the Service Locator to have an internal mapping from a constant public name like "MyDataSource" to the actual JNDI name used to look up the data source. This mapping could be stored in a configuration file so clients would not need to be changed when changing the JNDI name. [ January 28, 2005: Message edited by: David Harkness ]
Could please tell me the "MyDataSource" mapping should be specified in which configuration file. Is the struts-congif.xml file , as i use the Struts framework? Or is it the oracle-ds.xml file, as I use Oracle as my database?
Definitely not struts. If the oracle-ds.xml file is the configuration for your J2EE container (application server like WebLogic, WebSphere, JBoss, etc), then yes. Are you using OC4J (I think that's the name of Oracle's app server)?
Hi, My applocation server is JBoss. How does the code go and see that it has to read the datasource from oracle-ds.xml file in the client? I've given tried as what you have adviced me to do. And it does work out.
This is the code of the method of ServiceLocator class:
And finally I call the method in the client like this :
When the client tries to call the method - I get the folllowing error
javax.naming.NameNotFoundException: OracleDS not bound at servicelocator.ServiceLocator.getDataSource(ServiceLocator.java:249) at servicelocator.ServiceLocatorTester.main(ServiceLocatorTester.java:38)
Looking forward for the solution.
thanks & rgds, Sherryl [ January 31, 2005: Message edited by: Sherryl Philip ]
1. First make sure that OracleDS - DataSource is created in the JBOSS. I have n't used the JBOSS, but in weblogic you have the provision to view the jndi tree. If the DataSource is created properly then that entry must be present in the JNDI Tree. (Checking the DataSource in the app server level).
2. You need to set the initial context URL and Initial Context factory properties in the Initial Context if the appserver is different from your development box.
Hashtable ht = new Hashtable(); ht.put("INITIAL_CONTEXT_FACTORY", ....); ht.put("PROVIDER_URL", ....); Context ctx = new InitialContext(ht);
Please check the JBOSS manual for the above to get clear idea.