Programmatically access Websphere Application Server and its resources

jmxwebsphere

This is my very first question on StackOverflow so, please bear with me.

What am I trying to achieve?

I need to write a standalone program to access a particular instance or multiple instances of Websphere Application Server and get details from it. As far as my research goes, there are two ways to do this.

  1. Adaptors
  2. Connectors

I am currently taking up the 'Connectors' approach and that too the SOAP connector (for its firewall friendliness)

So, my code would be something like this..


// Initialize the AdminClient.
Properties adminProps = new Properties();

adminProps.setProperty("type", AdminClient.CONNECTOR_TYPE_SOAP );
adminProps.setProperty("host", "localhost");
adminProps.setProperty("port", "8880");
AdminClient adminClient = AdminClientFactory.createAdminClient(adminProps);

String query = "WebSphere:*";
//String query = "WebSphere:type=Server,*";
ObjectName queryName = new ObjectName(query);
Set s = adminClient.queryNames(queryName, null);
if (!s.isEmpty()) {
    iter = s.iterator();
    while (iter.hasNext()) {
        ObjectName nodeagent = (ObjectName) iter.next();
    System.out.println("*********************************************");
        System.out.println("KeyPropertyList: " + nodeagent.getKeyPropertyListString());
    }
}

With this piece of code, I am able to get the list of all the MBeans on that particular instance of the WAS (C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01) and it successfully prints the Key – Property list.

Now I have a list of MBeans. What next?
Link: _http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.javadoc.doc/web/mbeanDocs/index.html

Here is my query:

How do I get an instance of a particular MBean I am interested in and fetch all related properties?

For example:

AppManagement appM = AppManagementProxy.getJMXProxyForClient (adminClient);
System.out.println(appM.listApplications(null, null, null));

Would list all the application(s) on that particular instance of WAS

[query, SamplesGallery, ivtApp, DefaultApplication, PlantsByWebSphere]

I am interested in knowing more about the applications installed say, are they up and running? If so, the IP Address, build number, is it in maintenance, etc., (just quoting them as an example) If I can get all possible details of the application that the MBean could offer, then it would complete my task (partly)

The aforementioned is just an example and I would like to get more out of MBeans. So, please provide a solution / sample code that would help me out in getting information from any MBean the WAS instance has to offer. (Using JMX)

Additional Details:
IBM WebSphere Application Server, 7.0.0.0 (Base Installation)

Thanks in Advance,
AJ

Best Answer

IP address you could get indirectly by querying all servers and checking if the app is running on each of them, and then finding getting the host from each server. I'm not sure if build number is available. What does "in maintenance" mean?

You can get more information from the Application and J2EEApplication (JSR 88) MBeans. So, ObjectName("WebSphere:type=Application,name=myapp"), which is WebSphere-specific, or ObjectName("WebSphere:type=J2EEApplication,name=myapp").

You can get configuration information using ConfigServiceProxy and querying for the getid("/DefaultApplication:myapp/"). You can look at PROFILE_HOME/config/cells/CELL/applications/APP.ear/deployments/APP/deployment.xml to see the kind of information available from the config. You can match it up with the type information in WAS_HOME/web/configDocs/ starting with the appdeployment package.

Related Topic