title: Programmatically access Websphere Application Server and its resources
body: <p>This is my very first question on StackOverflow so, please bear with me.</p>
  
  <p>What am I trying to achieve?</p>
  
  <p>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.</p>
  
  <ol>
  <li>Adaptors</li>
  <li>Connectors</li>
  </ol>
  
  <p>I am currently taking up the 'Connectors' approach and that too the SOAP connector (for its firewall friendliness)</p>
  
  <p>So, my code would be something like this..</p>
  
  <hr>
  
  <pre><code>// 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());
      }
  }
  </code></pre>
  
  <hr>
  
  <p>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.</p>
  
  <p>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</p>
  
  <p>Here is my query:</p>
  
  <p>How do I get an instance of a particular MBean I am interested in and fetch all related properties?</p>
  
  <p>For example:</p>
  
  <pre><code>AppManagement appM = AppManagementProxy.getJMXProxyForClient (adminClient);
  System.out.println(appM.listApplications(null, null, null));
  </code></pre>
  
  <p>Would list all the application(s) on that particular instance of WAS</p>
  
  <p>[query, SamplesGallery, ivtApp, DefaultApplication, PlantsByWebSphere]</p>
  
  <p>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)</p>
  
  <p>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)</p>
  
  <p>Additional Details:
  IBM WebSphere Application Server, 7.0.0.0 (Base Installation)</p>
  
  <p>Thanks in Advance,
  AJ</p>