Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Recognize Application server.

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Iam developing a product which can be deployed on any web or application server. As different application or web servers have different lookup mechanisms for getting a connection object from the connection pool.

I want to know the server details on which my application is deployed, so that i can use server specific lookup mechanism.

Currently i am working on two servers. ( Weblogic9.2 and Tomcat5.5 ). Can these servers be recognized from my java application using any API.

I have done a hard look up at google, but i could not find a solution.

Please help me.

Thanks,
Venkat
[ October 05, 2008: Message edited by: Venkata Guru ]
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of coding to different servers, I'd use JNDI as the lookup mechanism. (Here's a tutorial on how to code that for a DataSource.) Then you can configure it in the web.xml for each server - no code changes needed.
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply, iam using JNDI lookup mechanism in my application, but coming to weblogic server, we need to pass some additional parameters to the Context object.

Here is the below code.

-----------


Hashtable<Object, String> ht = new Hashtable<Object, String>();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:80");
ht.put(Context.SECURITY_PRINCIPAL, "username");
ht.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext ctx = new InitialContext(ht);
DataSource newDataSource = (DataSource) ctx.lookup(serviceName);
conn = newDataSource.getConnection();


We need to pass an hashtable object as a parameter to the IntialContext object. Where as in Tomcat server, this hashtable does not come into picture.
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see. You can still write platform-independent code by keeping those parameters in the web.xml file as context parameters. Then this JNDI code can check for whether or not they're present, and use or not use the Hashtable accordingly.
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic