0 Replies Latest reply on Aug 30, 2007 4:57 AM by shankha

    java.lang.ClassCastException -

    shankha

      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 ??

      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)