我使用本教程https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html配置了Apache Tomcat 8,并生成了SSL证书.
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://10.16.70.161:9999/jmxrmi"); HashMap environment = new HashMap(); String[] credentials = new String[] { "user", "passw" }; environment.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxc = JMXConnectorFactory.connect(url, environment); MBeanServerConnection server = jmxc.getMBeanServerConnection(); Sets2 = server.queryNames(new ObjectName("Catalina:type=Server,*"), null); for (ObjectName obj : s2) { ObjectName objname = new ObjectName(obj.getCanonicalName()); System.out.println("serverInfo " + server.getAttribute(objname, "serverInfo")); System.out.println("address " + server.getAttribute(objname, "address")); System.out.println("stateName " + server.getAttribute(objname, "stateName")); }
我如何扩展此JMX客户端以将其与SSL证书一起使用?我在互联网上找不到任何好的例子.
您几乎就在那里,您的代码是正确的,只需使用keytool命令行实用程序将SSL证书添加到信任存储区后,使用以下命令行启动JMX客户端:
java -Djavax.net.ssl.trustStore=/your/path/to/truststore.jks \ -Djavax.net.ssl.trustStorePassword=truststore_pwd \ YourJMXClient