Programmatically Access Resource Environment Provider Settings in WebSphere Application Server

(that is a cross post from my IBM internal blog)

Last week I had to do some library on WebSphere 6 which uses configuration data stored in a [http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/c... Resource Environment Provider]. As I had a hard time to figure out how to access the configuration and especially the attributes, here some small code snippets which show the access of a resource environment provider.

In this first snippet you see how to access a resource environment provider which is defined on the node level:

{{{
ConfigService service = ConfigServiceFactory.getConfigService();
Session session = new Session();

ObjectName node1 = ConfigServiceHelper.createObjectName(null,
"Node", null);
ObjectName[] matches = service.queryConfigObjects(session,
null, node1, null);
node1 = matches[0]; // use the first node found

// direct search
ObjectName sampleProviderName = ConfigServiceHelper
.createObjectName(null,
"ResourceEnvironmentProvider",
"MySampleProvider");
matches = service.queryConfigObjects(session, node1,
sampleProviderName, null);
if (matches.length > 0)
{
sampleProviderName = matches[0]; // use the first provider found
}
// else do something different: create a new configuration or
// fail with an exception for example
}}}

If you've got the resource environment provider entry you have to browse through the configuration structure:

{{{
// search for the repository provider attributes
AttributeList value = service.getAttributes(session,
sampleProviderName, new String[] { "propertySet" }, false);
ObjectName propertySet = (ObjectName) ConfigServiceHelper
.getAttributeValue(value, "propertySet");

value = service.getAttributes(session, propertySet,
new String[] { "resourceProperties" }, false);
List resourceProperties = (List) ConfigServiceHelper
.getAttributeValue(value, "resourceProperties");
for (int i = 0; i < resourceProperties.size(); i++) {
// load all custom properties
ObjectName on = (ObjectName) resourceProperties.get(i);
String name = (String) service.getAttribute(session,
on, "name");
Object value = service.getAttribute(session, on,
"value"));
// now you can do something with the name and the value
}
}}}

The reason for first getting the ''propertySet'' and ''resourceProperties'' is in the structure of the configuration, you can see that in the resource.xml (found in the AppServer/profiles/wp_profile/config/cells/CELL/nodes/NODE directory):

{{{
<resources.env:ResourceEnvironmentProvider xmi:id="ResourceEnvironmentProvider_1272007360812" name="MySampleProvider">
<propertySet xmi:id="J2EEResourcePropertySet_1272007360855">
<resourceProperties xmi:id="J2EEResourceProperty_1272007360985" name="attribute_one" type="java.lang.String" value="value_one" required="true"/>
</propertySet>
</resources.env:ResourceEnvironmentProvider>
}}}

Resources:

User login

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
10 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Powered by Drupal