Any idea of how to access websphere environment variable from java code? I'd like to set the jndi name to environment variable and use this variable in the code instead of storing in properties file.
This sounds like you are trying to reinvent resource references. How
many levels of indirection do you think you need? There is already a
binding from the logical jndi name used in the program to the real jndi
name of the resource in the namespace, so what are you trying to
accomplish?
Presumably the java classes that are accessing the data source are
running in an application server? Which means that they are running in
the context of some EJB or some Web Application that called them? So you
would define your resource reference for the datasource on the calling
EJB or Webapp.
You seem to be confusing development time concepts (projects) with
runtime concepts.
What you are describing is exactly the purpose of the resource
reference. In your code you might lookup a reference binding of
"jdbc/myDB", but the actual JNDI name that you map it to can be changed
by the deployer - so in test you might bind it to a datasource with a
JNDI name of "jdbc/com/myco/myapp/test/myDB", but in production you bind
it to "jdbc/com/myco/myapp/prod/myDB"
Isn't this exactly what you are trying to do?
My opinion is that it's better to use the features that exist rather
than reinvent them. Otherwise why even bother using a standards-based
application server.
I see two aspects in your question :
1) How an application can discover on which cell / node / server it is
running ?
2) How to programmatically read websphere configuration in java ?
3) How to get configuration data for the server on which the
application is running ?
Unfornatulately, I don't have the time to give you an "out of the box"
answer but here are pieces of the answer :
How to discover on which cell/node/server/appName my app is running ?
============================================================
With "new javax.naming.InitialContext(new
Properties()).getNameInNamespace()"
you get "MyCell/nodes/MyNode/servers/MyServer"
How to read Websphere's Variable Substitution Entries with WsAdmin ?
===========================================================
Here is an extract of jython script that reads Websphere's Variable
Substitution Entries (you have to find the value of serverId)
serverId =
"server1(cells/MyCell/nodes/MyNode/servers/server1:server.xml#Server_1)"
variableSubstitutionEntriesUnsplit =
AdminConfig.list('VariableSubstitutionEntry', serverId)
variableSubstitutionEntries =
variableSubstitutionEntriesUnsplit.split(lineSeparator)
for variableSubstitutionEntry in variableSubstitutionEntries:
if len(variableSubstitutionEntry) > 0:
symbolicName = AdminConfig.showAttribute(variableSubstitutionEntry,
'symbolicName')
value = AdminConfig.showAttribute(variableSubstitutionEntry,
'value')
print offset + " <variableSubstitutionEntry symbolicName='" +
symbolicName + "' value='" + value + "' id='" +
variableSubstitutionEntry + "' />"
How to connect to Websphere Configuration Service (JMX) ?
==================================================
- Article "IBM WebSphere Developer Technical Journal: System
Administration for WebSphere Application Server V5 | Part 2 -- Writing
Your Own Administration Programs"
--> url :
http://www-128.ibm.com/developerworks/websphere/techjournal/0302_cundiff/cundiff.html
- see
com.ibm.websphere.management.AdminClientFactory.createAdminClient()
Which method of Websphere Configuration Service to use ?
==================================================
- Article "IBM WebSphere Developer Technical Journal: System
Administration for WebSphere Application Server V5 | Part 5 --
Programmatic Configuration"
--> url :
http://www-128.ibm.com/developerworks/websphere/techjournal/0307_wang/wang.html
- see
com.ibm.websphere.management.configservice.ConfigProxyService(AdminClient)
- see
com.ibm.websphere.management.configservice.ConfigService.queryConfigObjects(...)
Hope this helps,
Cyrille
------------------------------------
Cyrille Le Clerc
clec...@pobox.com
cyrille...@fr.ibm.com