Connecting to the MBean server
Connect to the MBean server programmatically, or by using a JMX client. You must establish a connection to the MBean server to use the JMX MBeans for managing Insight Server, solutions, and connectivity.
About this task
Procedure
- To connect to the MBean server programmatically, enable
the connection by using the following code:
private static MBeanServerConnection getConnection(String hostName, int port, String adminUsername, String adminPassword, String trustStorePath, String trustStorePassword) throws MalformedURLException, IOException { System.setProperty("javax.net.ssl.trustStore", trustStorePath); System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); HashMap<String, Object> environment = new HashMap<String, Object>(); environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client"); environment.put(JMXConnector.CREDENTIALS, new String[] { adminUsername, adminPassword }); environment.put("com.ibm.ws.jmx.connector.client.disableURLHostnameVerification", Boolean.TRUE); String jmxURL = "service:jmx:rest://" + hostName + ":" + port + "/IBMJMXConnectorREST"; JMXServiceURL url = new JMXServiceURL(jmxURL); JMXConnector connector = JMXConnectorFactory.newJMXConnector(url, environment); connector.connect(); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); return mbsc;} - To connect to the MBean server by using a JMX client:
- Set the class path for the JMX client to include the restConnector.jar and ia-management.jar.
For example:
set CLASSPATH=%CLASSPATH%;C:\IBM\ODMInsights890\runtime\wlp\clients\restConnector.jar;C:\IBM\ODMInsights890\runtime\ia\dev\api\ibm\ia-management.jarWhere the location of the restConnector.jar file is <InstallDir>/runtime/wlp/clients/restConnector.jar and the location of the ia-management.jar file is <InstallDir>/runtime/ia/dev/api/ibm/ia-management.jar.
- Start the JMX client, specifying the truststore location
and password as part of the launch command.
For example, to start jconsole on Windows, run the following command:
jconsole -J-Djava.class.path=<JAVA_HOME>\lib\jconsole.jar;<JAVA_HOME>\lib\tools.jar;C:\IBM\ODMInsights890\runtime\wlp\clients\restConnector.jar -J-Djavax.net.ssl.trustStore=C:\IBM\ODMInsights890\runtime\wlp\usr\servers\cisDev\resources\security\key.jks -J-Djavax.net.ssl.trustStorePassword="tester" -J-Dcom.ibm.ws.jmx.connector.client.disableURLHostnameVerification=true -debugWhere the truststore location is <WLP_USER_DIR>/servers/server_name/resources/security/key.jks.
- Establish a remote connection to the MBean server by
using the JMX client and the REST connector.
For example:
service:jmx:rest://localhost:9443/IBMJMXConnectorRESTWhere localhost is the name of the MBean server host and 9443 is the secure server port. The user name and password for the default cisDev server is tester.
Provide authentication credentials to the MBean server by entering the user name and password for an administrator account.
The following client example connects to the ServerAdminMXBean and prints the names of the running servers.
public static void main(String[] args) throws Exception{ String hostName = "localhost"; int port = 9443; String adminUsername = "tester"; String adminPassword = "tester"; String trustStorePath = "<WLP_USER_DIR>/servers/cisDev/resources/security/key.jks"; String trustStorePassword = "tester"; MBeanServerConnection mbeanConn = JMXClient.getConnection(hostName, port, adminUsername, adminPassword, trustStorePath, trustStorePassword); //ServerAdminMXBean ObjectName objectNameServerAdmin = new ObjectName("com.ibm.ia:type=ServerAdmin"); ServerAdminMXBean beanServerAdmin = JMX.newMXBeanProxy(mbeanConn, objectNameServerAdmin, ServerAdminMXBean.class); if(beanServerAdmin != null){ for(Iterator<String> itServers = beanServerAdmin.getAllServers().iterator(); itServers.hasNext();){ String s = (String) itServers.next(); System.out.println("Server found: " + s); } } }
- Set the class path for the JMX client to include the restConnector.jar and ia-management.jar.