Etablissement d'une connexion serveur Liberty à un bean géré JMX

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

  1. Configurez l'environnement.

    Les fichiers dont vous avez besoin se trouvent dans le répertoire rép_base_liberty/clients/jython.

    1. Copiez le fichier lib/restConnector.py file dans le répertoire rép_base_jython/Lib.
    2. 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
  2. Exécutez l'utilitaire.
    Exemple 1 : Obtention d'une connexion simple avec 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
    Définit le chemin dans lequel est stocké le fichier de clés SSL
    JMXRESTConnector.trustStorePassword
    Définit le mot de passe pour la clé
    JMXRESTConnector.connect(hôte,port,utilisateur,mot de passe)
    Crée un connecteur pour le serveur
    JMXRESTConnector.connect(hôte,port,mappe)
    Crée un connecteur avec des propriétés utilisateur
    JMXRESTConnector.getMBeanServerConnection
    Obtient une connexion au serveur de bean géré
    JMXRESTConnector.disconnect()
    Ferme la connexion

Que faire ensuite

Après l'établissement d'une connexion au serveur MBean, vous pouvez effectuer des appels au serveur MBean à l'aide de la méthode invoke(...) .

Remarque : Vous pouvez télécharger une bibliothèque de scripts Jython depuis le référentiel Liberty.

Icône indiquant le type de rubrique Rubrique Tâche

Dispositions pour les centres de documentation | Commentaires


Icône d'horodatage Dernière mise à jour: Wednesday, 2 September 2015
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_admin_serverconnection
Nom du fichier : twlp_admin_serverconnection.html