How to connect to WebSphere Application Server using Custom Administrative Client Program

How to connect to WebSphere Application Server using Custom Administrative Client Program


Purpose – To connect to WebSphere Application Server using Custom Administrative Client Program

Pre-requisites
JVM – IBM J9 VM (1.6.0)
WAS ND – 8.5.5.1

Websphere Application server and hosted applications could be administered through tools (i.e adminclient, Admin console, command line utilities) that come with the product or through Java API’s

In this post we will try to implement the custom java program using the AdminClient for connecting to Websphere environment.

1. Make sure that the Application server (in Standalone)or Deployment manager (in ND version) is up and running.
2. Get the SOAP connector port number
3. If admin security is enabled, get the user id and password used to connect to Websphere administrative console
4. If SSL is enable, get the locations of trust store and key store files.
5. Make sure that you are using the correct password for accessing the trust store and key store files
6. Make sure to include the following Jar files in the classpath directory available at below locations

com.ibm.ws.admin.client_8.5.0.jar – <WAS_HOME>/runtimes/
com.ibm.ws.security.crypto.jar – – <WAS_HOME>/plugins/

Here is a snippet of code to for getting the connection to Deployment manager using AdminClient object

package com.ibm.testing;

import java.util.Date;
import java.util.Properties;
import java.util.Set;

import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;

import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.websphere.management.exception.ConnectorException;

public class AdminClientExampleSoap
{

    private AdminClient adminClient;
    private ObjectName nodeAgent;

    public static void main(String[] args)
    {
       AdminClientExampleSoap ace = new AdminClientExampleSoap();

       // Create an AdminClient
       ace.createAdminClient();

       // Find a NodeAgent MBean
       ace.getNodeAgentMBean(“CORENode01”);

    }

    private void createAdminClient()
    {
        // Set up a Properties object for the JMX connector attributes
        Properties connectProps = new Properties();
        connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
        connectProps.setProperty(AdminClient.CONNECTOR_HOST, “localhost”);
        connectProps.setProperty(AdminClient.CONNECTOR_PORT, “8879”);
        connectProps.setProperty(AdminClient.USERNAME, “dmgr”);
        connectProps.setProperty(AdminClient.PASSWORD, “dmgr”);

connectProps.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED, “true”);
connectProps.setProperty(“javax.net.ssl.trustStore”, “D:/WASInstall/WAS/profiles/Dmgr01/etc/trust.p12”);
connectProps.setProperty(“javax.net.ssl.keyStore”, “D:/WASInstall/WAS/profiles/Dmgr01/etc/key.p12”);
connectProps.setProperty(“javax.net.ssl.trustStorePassword”, “ikeyman@1”);
connectProps.setProperty(“javax.net.ssl.keyStorePassword”, “ikeyman@1”);
     
     
        // Get an AdminClient based on the connector properties

        try
        {
            System.out.println(“Trying to connect….”);
            adminClient = AdminClientFactory.createAdminClient(connectProps);
        }
        catch (ConnectorException e)
        {
            e.printStackTrace();
            System.out.println(“Exception creating admin client: ” + e);
            System.exit(-1);
        }

        System.out.println(“Connected to DeploymentManager”);
    }
 
    private void getNodeAgentMBean(String nodeName)
    {
        // Query for the ObjectName of the NodeAgent MBean on the given node

        try
        {
            String query = “WebSphere:type=NodeAgent,node=” + nodeName + “,*”;
            ObjectName queryName = new ObjectName(query);
            Set s = adminClient.queryNames(queryName, null);
            if (!s.isEmpty())
            {
                nodeAgent = (ObjectName)s.iterator().next();
            System.out.println(“Node Agent : ” + nodeAgent.toString());
         
            }
            else
            {
                System.out.println(“Node agent MBean was not found”);
                System.exit(-1);
            }
        }
        catch (MalformedObjectNameException e)
        {
            System.out.println(e);
            System.exit(-1);
        }
        catch (ConnectorException e)
        {
            System.out.println(e);
            System.exit(-1);
        }
     
        System.out.println(“Found NodeAgent MBean for node ” + nodeName);
    }

}

Output
Trying to connect….
Connected to DeploymentManager
Node Agent : WebSphere:name=NodeAgent,process=nodeagent,platform=common,node=CORENode01,diagnosticProvider=true,version=8.5.5.1,type=NodeAgent,mbeanIdentifier=NodeAgent,cell=CORECell01,spec=1.0
Found NodeAgent MBean for node CORENode01

================================================================

Hope you enjoyed reading this article. Thank you.

1 COMMENT

comments user
21cssIndia

This comment has been removed by a blog administrator.