Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing Websphere Variables Programatically

1,905 views
Skip to first unread message

shankar....@erieinsurance.com

unread,
Jul 22, 2005, 10:36:58 AM7/22/05
to
Hi,

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.

Paul Ilechko

unread,
Jul 22, 2005, 11:42:36 AM7/22/05
to
shankar....@erieinsurance.com wrote:


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?

shankar....@erieinsurance.com

unread,
Jul 22, 2005, 12:01:23 PM7/22/05
to
The resource that Iam trying to use is not an JNDI to refer EJB. Rather JDNI to refer XA datasource. As you know that, Web project and EJB project has deployment descriptors to specify resource references. But is not available for simple Java Project (you can consider it as utility project) and I am referencing the DB datasource JNDI in this project. Please correct me if iam wrong. Thanks.

Paul Ilechko

unread,
Jul 22, 2005, 1:04:16 PM7/22/05
to
shankar....@erieinsurance.com wrote:


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.

shankar....@erieinsurance.com

unread,
Jul 22, 2005, 2:16:57 PM7/22/05
to
I understood your point. The reason I am asking for accessing websphere variable is that, we have a separate group who takes care of deploying this application even in test environment. So if i could use a websphere variable in my code for JNDI. Then deployment group can just change websphere variable according to the JNDI that he/she configures in Test WAS. In that way we dont need to have this property(JNDI string) in either .class file or .properties file. This is my actual intent. Feel free to comment on this and please let me know a better way of doing (if any). Thanks.

Paul Ilechko

unread,
Jul 22, 2005, 3:09:19 PM7/22/05
to
shankar....@erieinsurance.com wrote:


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?

shankar....@erieinsurance.com

unread,
Jul 22, 2005, 4:25:32 PM7/22/05
to
Yes Paul. But this requires deployer to modify the deployment descriptor and publish the application.
But, I am planning in such a way that he does'nt need to modify any file within the application. Wouldnt be nice if he doesnt touch any files within our application and still everything goes fine? Whats your opinion?

Paul Ilechko

unread,
Jul 22, 2005, 4:38:08 PM7/22/05
to

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.

shankar....@erieinsurance.com

unread,
Jul 22, 2005, 5:05:19 PM7/22/05
to
Thanks. But, I am still curious know how to access websphere envrionment variable from code :)

Ash

unread,
Jul 23, 2005, 11:33:10 PM7/23/05
to
I'd be interested in that too. For example, I'd like my application to
behave differently if global security is enabled in WAS or not.

Cyrille Le Clerc

unread,
Jul 26, 2005, 6:21:04 PM7/26/05
to
Hello,

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

0 new messages