Programmatically Access Resource Environment Provider Settings in WebSphere Application Server
Submitted by matthias hub on Mon, 04/26/2010 - 11:17
(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 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:
If you've got the resource environment provider entry you have to browse through the configuration structure:
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:
Last week I had to do some library on WebSphere 6 which uses configuration data stored in a 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:
- Main information source is the WebSphere Application Server Info Center: http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/c...
- Related developer example: http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/c...
- Old but nevertheless an informative DeveloperWorks article: http://www.ibm.com/developerworks/websphere/techjournal/0307_wang/wang.html
Navigation
User login
matthias hub's tweets
- schöne kleine Anleitung: stefanglase.de | Gradle unter Mac OS X installieren: http://t.co/iAtn1HC7 — 9 weeks 5 days ago
- @wespennest haste pingelsn nicht gesehen? — 11 weeks 6 days ago
- Nu hats tatsächlich geklappt, freie Plätze für uns! (@ Champa Thai-Lao-Imbiss) http://t.co/7h9dBaRn — 12 weeks 1 day ago
- Wow, jetzt erst geht es weiter mit der Fahrt... #A81 — 13 weeks 5 days ago
- So, und im nächsten Stau: Vollsperrung auf der A81 aufgrund eines Unfalls mit einem Gefahrguttransporter... müde... — 13 weeks 5 days ago
- 1 of 65
- ››
