Développement d'un client Java JMX pour Liberty
Vous pouvez développer une application client Java™ Management Extensions (JMX) pour accéder au connecteur REST sécurisé de Liberty.
Pourquoi et quand exécuter cette tâche
A l'aide d'une application client distante JMX, vous pouvez administrer Liberty au moyen de la programmation JMX.
Procédure
- Développez un exemple de client JMX. Le connecteur REST prend en charge l'API JMX standard. Dans le cas d'un serveur Liberty démarré avec la fonction restConnector-1.0
configurée, le contenu de ${server.output.dir}/logs/state/com.ibm.ws.jmx.rest.address peut être utilisé pour instancier un nouvel objet JMXServiceURL.
import javax.management.remote.JMXServiceURL; import javax.management.MBeanServerConnection; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import java.util.HashMap; public class Test { public static void main(String[] args) { System.setProperty("javax.net.ssl.trustStore", <truststore location>); System.setProperty("javax.net.ssl.trustStorePassword", <truststore password>); //If the type of the trustStore is not jks, which is default, //set the type by using the following line. System.setProperty("javax.net.ssl.trustStoreType", <truststore type>); try { 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[] { "bob", "bobpassword" }); JMXServiceURL url = new JMXServiceURL("service:jmx:rest://<host>:<port>/IBMJMXConnectorREST"); JMXConnector connector = JMXConnectorFactory.newJMXConnector(url, environment); connector.connect(); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); } catch(Throwable t) { ... } } }
- Facultatif : Désactivez la vérification du nom d'hôte pour les certificats SSL. Les certificats qui sont installés avec Liberty peuvent ne pas contenir le nom d'hôte de l'endroit où le serveur s'exécute. Si vous voulez
désactiver la vérification du nom d'hôte des certificats SSL, vous pouvez associer la propriété système com.ibm.ws.jmx.connector.client.disableURLHostnameVerification à la valeur true.
La vérification du nom d'hôte sera alors désactivée pour toutes les connexions. Pour désactiver la vérification du nom d'hôte sur une base de connexion
individuelle, transmettez la propriété en tant que nouvel élément environment lorsque vous créez la connexion JMX :
HashMap<String, Object> environment = new HashMap<String, Object>(); environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client"); environment.put("com.ibm.ws.jmx.connector.client.disableURLHostnameVerification", Boolean.TRUE); environment.put(JMXConnector.CREDENTIALS, new String[] { "bob", "bobpassword" }); ...
- Facultatif : Configurez les paramètres de connecteur REST JMX à l'aide de la mappe d'environnement.
... HashMap<String, Object> environment = new HashMap<String, Object>(); environment.put("com.ibm.ws.jmx.connector.client.rest.maxServerWaitTime", 0); environment.put("com.ibm.ws.jmx.connector.client.rest.notificationDeliveryInterval", 65000); ...
- Facultatif : Le connecteur REST Liberty permet d'utiliser une fabrique de sockets SSL personnalisés spécifique pour obtenir des sockets. Si l'exception javax.net.ssl.SSLHandshakeException:
com.ibm.jsse2.util.j: PKIX path building failed: java.security.cert.CertPathBuilderException: unable to find valid certification
path to requested target s'affiche, vous pouvez créer votre propre SSLContext à partir de vos propres magasins de clés puis utiliser le SocketFactory de ce contexte avec le
connecteur REST.
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream inputStream = new FileInputStream("myTrustStore.jks"); trustStore.load(inputStream, "password".toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(trustStore); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustManagers, null); Map<String, Object> environment = new HashMap<String, Object>(); environment.put(ConnectorSettings.CUSTOM_SSLSOCKETFACTORY, sslContext.getSocketFactory()); environment.put(ConnectorSettings.DISABLE_HOSTNAME_VERIFICATION, true); environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client"); environment.put(JMXConnector.CREDENTIALS, new String[] { "admin", "password" }); JMXServiceURL url = new JMXServiceURL("REST", "myhost", 9443, "/IBMJMXConnectorREST"); jmxConn = JMXConnectorFactory.connect(url, environment);
Rubrique parent : Configuration d'une connexion JMX sécurisée à Liberty
Tâches associées:


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_dev_jmxclient
Nom du fichier : twlp_dev_jmxclient.html