Vous pouvez utiliser des scripts Jython pour établir une
connexion serveur Liberty à un bean géré JMX
(Java™ Management Extensions).
Avant de commencer
Vous devez obtenir et installer la version Jython de votre choix
pour pouvoir effectuer cette procédure. Sans Jython,
les instructions échoueront.
Procédure
- Configurez l'environnement.
Les fichiers dont vous avez besoin se trouvent dans le répertoire rép_base_liberty/clients/jython.
- Copiez le fichier lib/restConnector.py file dans le répertoire rép_base_jython/Lib.
- Définissez le chemin d'accès aux classes pour restConnector.jar dans le répertoire rép_base_liberty/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()
Exemple 2 : Obtention d'une connexion avancée avec
connector.connect(host,port,map) associé à des propriétés fournies par l'utilisateur
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()
Exemple 3 : Enregistrement d'un programme d'écoute de notifications
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
Que faire ensuite
After a connection to the MBean server is established,
you can make calls to the MBean server by using the invoke(...) method.
Remarque : A library of Jython scripts is available for you to download from the
Liberty Repository.