README 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. The script in this directory provides a utility for establishing a Liberty
  2. JMX MBean server connection. This has been tested for Jython 2.5.3.
  3. 1) Environment set up
  4. a. Set the classpath to include the restConnector.jar
  5. e.g) WINDOWS
  6. set CLASSPATH=${wlp.install.dir}\clients\restConnector.jar
  7. e.g) LINUX / UNIX
  8. export CLASSPATH=${wlp.install.dir}/clients/restConnector.jar
  9. b. Set the jython path to include the restConnector.py
  10. e.g) WINDOWS
  11. set JYTHONPATH=${wlp.install.dir}\clients\jython\restConnector.py
  12. e.g) LINUX / UNIX
  13. export JYTHONPATH=${wlp.install.dir}/clients/jython/restConnector.py
  14. 2) Examples
  15. The following two examples show how to get a Liberty JMX MBean server
  16. connection using the utility:
  17. Example 1 - Simple connection using connector.connect(host,port,user,password)
  18. from restConnector import JMXRESTConnector
  19. JMXRESTConnector.trustStore = "c:/key.jks"
  20. JMXRESTConnector.trustStorePassword = "Liberty"
  21. connector = JMXRESTConnector()
  22. connector.connect("foo.bar.com",9443,"theUser","thePassword")
  23. mconnection = connector.getMBeanServerConnection()
  24. # mconnection.invoke(...)
  25. connector.disconnect()
  26. Example 2 - Advanced connection using connector.connect(host,port,map) with
  27. user provided properties
  28. import java
  29. import javax
  30. import jarray
  31. import com.ibm.websphere.jmx.connector.rest
  32. import com.ibm.ws.jmx.connector.client.rest
  33. map=java.util.HashMap()
  34. map.put("jmx.remote.provider.pkgs","com.ibm.ws.jmx.connector.client")
  35. map.put(javax.management.remote.JMXConnector.CREDENTIALS,jarray.array(["theUser","thePassword"],java.lang.String))
  36. map.put(com.ibm.websphere.jmx.connector.rest.ConnectorSettings.READ_TIMEOUT,2*60*1000)
  37. map.put(com.ibm.websphere.jmx.connector.rest.ConnectorSettings.DISABLE_HOSTNAME_VERIFICATION, True)
  38. connector = JMXRESTConnector()
  39. connector.connect("foo.bar.com",9443,map)
  40. mconnection = connector.getMBeanServerConnection()
  41. # mconnection.invoke(...)
  42. connector.disconnect()
  43. The following example shows how to register a notification listener:
  44. Example 3 - Notification listener
  45. import java
  46. import javax
  47. from restConnector import JMXRESTConnector
  48. from restConnector import BaseNotificationListener
  49. class SampleNotificationListener(BaseNotificationListener):
  50. def __init__(self):
  51. pass
  52. def handleNotification(self,notification,handback):
  53. print "Notification received:"
  54. print " Source: " + notification.getSource().toString()
  55. print " Type: " + notification.getType()
  56. print " Message: " + notification.getMessage()
  57. # main starts here
  58. JMXRESTConnector.trustStore = "c:/key.jks"
  59. JMXRESTConnector.trustStorePassword = "Liberty"
  60. connector = JMXRESTConnector()
  61. connector.connect("foo.bar.com",9443,"theUser","thePassword")
  62. mconnection = connector.getMBeanServerConnection()
  63. listener=SampleNotificationListener()
  64. handback=java.lang.Object()
  65. notifier1=javax.management.ObjectName("web:name=Notifier1")
  66. mconnection.addNotificationListener(notifier1,listener,None,handback)
  67. 3) API
  68. * JMXRESTConnector.trustStore - Set the path to the SSL key store file
  69. * JMXRESTConnector.trustStorePassword - Set the password for the key
  70. * JMXRESTConnector.connect(host,port,user,password) - Create a connector to the server
  71. * JMXRESTConnector.connect(host,port,map) - Create a connector with user properties
  72. * JMXRESTConnector.getMBeanServerConnection - Get a connection to the MBean server
  73. * JMXRESTConnector.disconnect() - Close the connection
  74. For more info, refer to the InfoCenter "Establishing a JMX MBean Liberty server connection"