[jboss-user] [Beginners Corner] - java.lang.ClassCastException -

shankha do-not-reply at jboss.com
Thu Aug 30 04:57:10 EDT 2007


Hi,
        I want to get the reference of the MBeanServer of my running JBOSS from my standalone program.

And on the MBeanServer  instance I want to invoke getVersionName() of the MBean Server.

But after getting the Server Object Instance Class I can not type case to the org.jboss.system.server.ServerImpl.

Code is given below :  Can My Approach is OK ??

anonymous wrote : Hashtable env = new Hashtable();
  |             String factory = "org.jnp.interfaces.NamingContextFactory";
  |             env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
  |             String url1 = "jnp://localhost:1099";
  |             env.put(Context.PROVIDER_URL, url1);
  |             Context ctx = new InitialContext(env);
  | 
  | 
  |             MBeanServerConnection mconn = (MBeanServerConnection)ctx.lookup("jmx/invoker/RMIAdaptor");
  |             if(null!=mconn){
  | 
  |                 ObjectName serverObj = new ObjectName("jboss.system:type=Server");
  |                 System.out.println("Version = " + (String)mconn.getAttribute(serverObj, new String("Version")));
  |                 ObjectInstance serverObjInst =  mconn.getObjectInstance(serverObj);
  |                 System.out.println(serverObj + "\n\t Server Object Instance Class Name =" + serverObjInst.getClassName());
  | 
  |    
  |                 if(mconn.isInstanceOf(serverObj,"org.jboss.system.server.ServerImpl")){
  | 
  |                     System.out.println("-----------------------------");
  | 
  |                     org.jboss.system.server.ServerImpl serverImpl = (org.jboss.system.server.ServerImpl)mconn;
  | 
  |                     System.out.println("@@ --- MBean Server Version name =    "+serverImpl.getVersionName());
  |                 }


--------------------------------------------------------------------------------
I got the following exception 

java.lang.ClassCastException: $Proxy0
	at com.test.client.MDBLocater.test(MDBLocater.java:56)
	at com.test.client.MDBLocater.main(MDBLocater.java:130)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079486#4079486

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079486



More information about the jboss-user mailing list