如何为远程JMX连接设置自定义RMI客户端套接字工厂?

时间:2018-06-21 03:24:43

标签: ssl rmi jmx

我正在研究用于从多个安全JMX服务器中获取数据的原型应用程序。我正在使用自定义ssl rmi工厂,该工厂使用适当的信任库和密钥库创建套接字。但是,JMX连接器存根不会调用它。

相反,我在客户端应用程序中收到此错误

java.rmi.ConnectIOException: non-JRMP server at remote endpoint
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:248)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
    at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
    at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2404)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:308)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
    at Client.main(Client.java:86)

服务器

HashMap env = new HashMap();   
SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory();
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE,ssf);

JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://localhost:9999/server");
JMXConnectorServer cs =  JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

System.out.println("\nStart the RMI connector server");
cs.start();

客户

HashMap env = new HashMap();        
SslRMIClientSocketFactory csf1 = new CustomSslRMIClientSocketFactory();
RMIClientSocketFactory csf2 = RMISocketFactory.getDefaultSocketFactory();

env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf1);
env.put("com.sun.jndi.rmi.factory.socket", csf2);        

JMXServiceURL url =  new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/server");
JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

System.out.println("connection id " + jmxc.getConnectionId());

运行原型应用程序的步骤

  • 在端口9999上启动rmiregistry(不安全)
  • java -Djavax.net.ssl.keyStore = config / keystore -Djavax.net.ssl.keyStorePassword =密码服务器
  • java客户端

0 个答案:

没有答案