• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

Service Locator Pattern

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Please do help me.

Thanks.

Regards,
Sherryl
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sherryl Philip
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?

Thanks again.

regards,
Sherryl
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
Sherryl Philip
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sherryl Philip,

Please follow the steps to avoid the error:

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.
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic