0

有关 Java 管理的文档中,在标题为“使用 JMX 远程 API 模拟开箱即用管理”的部分(见页面底部)中,它向您展示了如何通过 JMX 手动公开您的 MBeanServer。像这样的东西:

public static void main(String[] args) throws IOException {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final Map<String, Object> env = new HashMap<String, Object>();

    final SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
    env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    final SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory();
    env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);

    final int port = 32154;
    System.setProperty("java.rmi.server.randomIDs", "true");
    final Registry registry = LocateRegistry.createRegistry(port /*, csf, ssf */);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + port + "/jmxrmi");
    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
    cs.start();

如果您尝试运行此代码,则会重复抛出此异常(并且您无法远程连接到服务器):

26-Nov-2015 16:42:21:085: [sun.rmi.transport.tcp - FINE] [14]: RMI TCP Connection(4)-10.210.50.223: terminated with exception:

Exception in 14: Received fatal alert: certificate_unknown

javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
  at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
  at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1822)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1004)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
  at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:818)
  at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
  at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
  at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
  at java.io.DataInputStream.readInt(DataInputStream.java:370)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:686)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)

我想“一定是注册表不是用相关的套接字工厂创建的”,所以我取消了相关参数的注释LocateRegistry.createRegistry。但是现在抛出了这个异常(并且应用程序无法启动)

Exception in thread "main" java.io.IOException: Cannot bind to URL [rmi://:32154/jmxrmi]: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: non-JRMP server at remote endpoint]
  at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:804)
  at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:417)
  at gsa.core.monitor.ExposeMBeansViaSsl.main(ExposeMBeansViaSsl.java:32)

注意:应用程序在设置相关javax.net.ssl系统属性的情况下运行,如教程中所述。有谁知道发生了什么?

4

0 回答 0