You can use Jython-based scripts to establish a Java™ Management Extensions (JMX)
MBean Liberty server connection.
Before you begin
You must obtain and install the Jython version of your choice
before you can perform this procedure. Without a Jython runtime,
the instructions will fail.
Procedure
- Set up the environment.
The files that you
need are located in liberty_home/clients/jython.
- Copy the lib/restConnector.py file
to jython_home/Lib.
- Set the classpath for restConnector.jar in liberty_home/clients.
set CLASSPATH=%CLASSPATH%;c:\wlp\clients\restConnector.jar
- Run the utility.
Example 1: Getting
a simple connection using
connector.connect(host,port,user,password)from restConnector import JMXRESTConnector
JMXRESTConnector.trustStore = "c:/key.jks"
JMXRESTConnector.trustStorePassword = "Liberty"
connector = JMXRESTConnector()
connector.connect("foo.bar.com",9443,"theUser","thePassword")
mconnection = connector.getMBeanServerConnection()
# mconnection.invoke(...)
connector.disconnect()
Example 2: Getting
an advanced connection using
connector.connect(host,port,map) with user-provided properties
import java
import javax
import jarray
import com.ibm.websphere.jmx.connector.rest
import com.ibm.ws.jmx.connector.client.rest
map=java.util.HashMap()
map.put("jmx.remote.provider.pkgs","com.ibm.ws.jmx.connector.client")
map.put(javax.management.remote.JMXConnector.CREDENTIALS,jarray.array(["theUser","thePassword"],java.lang.String))
map.put(com.ibm.ws.jmx.connector.client.rest.ClientProvider.READ_TIMEOUT,2*60*1000)
map.put(com.ibm.websphere.jmx.connector.rest.ConnectorSettings.DISABLE_HOSTNAME_VERIFICATION, True)
connector = JMXRESTConnector()
connector.connect("foo.bar.com",9443,map)
mconnection = connector.getMBeanServerConnection()
# mconnection.invoke(...)
connector.disconnect()
Example 3: Registering
a notification listener
import java
import javax
from restConnector import JMXRESTConnector
from restConnector import BaseNotificationListener
class SampleNotificationListener(BaseNotificationListener):
def __init__(self):
pass
def handleNotification(self,notification,handback):
print "Notification received:"
print " Source: " + notification.getSource().toString()
print " Type: " + notification.getType()
print " Message: " + notification.getMessage()
# main starts here
JMXRESTConnector.trustStore = "c:/key.jks"
JMXRESTConnector.trustStorePassword = "Liberty"
connector=JMXRESTConnector()
connector.connect("foo.bar.com",9443,"theUser","thePassword")
mconnection=connector.getMBeanServerConnection()
listener=SampleNotificationListener()
handback=java.lang.Object()
notifier1=javax.management.ObjectName("web:name=Notifier1")
mconnection.addNotificationListener(notifier1,listener,None,handback)
- JMXRESTConnector.trustStore
- Sets the path to where the SSL key file is stored
- JMXRESTConnector.trustStorePassword
- Sets the password for the key
- JMXRESTConnector.connect(host,port,user,password)
- Creates a connector to the server
- JMXRESTConnector.connect(host,port,map)
- Creates a connector with user properties
- JMXRESTConnector.getMBeanServerConnection
- Gets a connection to the MBean server
- JMXRESTConnector.disconnect()
- Closes the connection
What to do next
After a connection to the MBean server is established,
you can make calls to the MBean server by using the invoke(...) method.
Note: A library of Jython scripts is available for
you to download from the
Liberty
Repository.