java.lang.ClassCastException: com.sun.jndi.rmi.registry.RegistryContext
Hello all.
I'm new at JMX and trying to use it in our system
The code looks like that
//create server
JMXServiceURL addr =new JMXServiceURL("rmi","127.0.0.1", port);
RMIConnectorServer connector =new RMIConnectorServer(addr, null, server);
JMXHelper.registerMBeanOrAdapter(server, name+",type=server", connector);
connector.start();
//create server connection
JMXServiceURL url=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+InetAddress.getByAddress(newbyte[]{127, 0, 0, 1}).getHostAddress()+":"+1099);
JMXConnector jmxc=JMXConnectorFactory.connect(url,null);
MBeanServerConnection mbsc=jmxc.getMBeanServerConnection();
I've gotten the exception, given in subject
java.lang.ClassCastException: com.sun.jndi.rmi.registry.RegistryContext
if i do not create server with command//connector.start();
and use "c:>rmiregistry 1099" i get the same exception
i do something wrong, but can not find it.
What am i wrong in?
Message was edited by:
NIkon_DSL
[1519 byte] By [
NIkon_DSLa] at [2007-11-27 7:34:26]

# 3
I think possibly the exception may be missleading, and more an invalid url. I am able to connect successfully with the following. I first start the the rmi server on 7979 like c:\>rmiregistry 7979. Then Server, then Client:
public class Server {
public static void main(String[] args) throws Exception {
MBeanServer server = MBeanServerFactory.createMBeanServer("mydomain");
JMXServiceURL addr = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:7979/server");
RMIConnectorServer connector = new RMIConnectorServer(addr, null, server);
//JMXHelper.registerMBeanOrAdapter(server, name+",type=server", connector);
server.registerMBean(connector, new ObjectName("JMXBookAgent:type=server"));
connector.start();
System.out.println("test started");
}
}
public class Client {
public static void main(String[] args) throws Exception {
JMXServiceURL url=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:7979/server");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc=jmxc.getMBeanServerConnection();
System.out.println("found " + mbsc.queryMBeans(null, null).size() + " mbeans");
}
}