2 Replies Latest reply on Aug 9, 2006 8:49 AM by mo momo

    how to get a user defined object invoked by mbeanserver in w

    mo momo Newbie


      the mbean implemetation:
      public class ModelService extends ServiceMBeanSupport implements ModelServiceMBean {
      public ModelObj getModelObj(String id) {
      ModelObj obj = new ModelObj();
      some action here;
      returen obj;
      }
      }

      ModelObj is a simple pojo I defined,there're only some getter and setter

      the mbean definition:


      the web service method code as follows:
      public String getModelName(String id) {
      try {
      MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
      Class clazz = server.getClassLoaderRepository().loadClass("jboss.mbean.model.ModelObj");
      ObjectName oname = new ObjectName("jboss.momo:service=ModelSvr");
      String[] sig = { String.class.getName() };
      Object[] opArgs = { new String("A01") };
      Object result = server.invoke(oname, "getModelObj", opArgs, sig);
      ModelObj mo = (ModelObj)clazz.cast(result);//some thing error,I wanna make the return object to cast to my defined object to invoke more operation,but just here comes some error "java.lang.ClassCastException: jboss.mbean.model.ModelObj"
      return mo.getName();
      } catch (Exception e) {
      e.printStackTrace();
      return null;
      }
      }

      the web service definition:



      <beanMapping languageSpecificType="java:jboss.mbean.model.ModelObj" qname="ns7:ModelSvc" xmlns:ns7="ModelSvc"/>


      when in other client(command line run mode)
      Object result = server.invoke(oname, "getModelObj", opArgs, sig);
      can be write like this:
      //MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "10.1.0.2");
      Context iniCtx = new InitialContext(env);
      RMIAdaptor server = (RMIAdaptor) iniCtx.lookup("jmx/rmi/RMIAdaptor");
      ModelObj result = (ModelObj)server.invoke(oname, "getModelObj", opArgs, sig);
      this will not throws java.llang.ClassCastException

        • 1. Re: how to get a user defined object invoked by mbeanserver
          mo momo Newbie

          how to get a user definition object invoked by mbeanserver in web service
          I just can't cast the returned object to my defined object

          the mbean implemetation:

          public class ModelService extends ServiceMBeanSupport implements ModelServiceMBean {
           public ModelObj getModelObj(String id) {
           ModelObj obj = new ModelObj();
           some action here;
           returen obj;
           }
          }

          ModelObj is a simple pojo I defined,there're only some getter and setter
          the mbean definition:
          <mbean code="jboss.mbean.model.ModelService" name="jboss.momo:service=ModelSvr"/>

          the web service method code as follows:
          public String getModelName(String id) {
           try {
           MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
           Class clazz = server.getClassLoaderRepository().loadClass("jboss.mbean.model.ModelObj");
           ObjectName oname = new ObjectName("jboss.momo:service=ModelSvr");
           String[] sig = { String.class.getName() };
           Object[] opArgs = { new String("A01") };
           Object result = server.invoke(oname, "getModelObj", opArgs, sig);
           ModelObj mo = (ModelObj)clazz.cast(result);
          ///////some thing error,I wanna make the return object to cast to my defined object to invoke more operation,but just here comes some error "java.lang.ClassCastException: jboss.mbean.model.ModelObj"
           return mo.getName();
           } catch (Exception e) {
           e.printStackTrace();
           return null;
           }
          }

          the web service definition:
          <service name="ModelSvc" provider="java:RPC">
           <parameter name="allowedMethods" value="*"/>
           <parameter name="className" value="webservice.services.ModelParser"/>
           <beanMapping languageSpecificType="java:jboss.mbean.model.ModelObj" qname="ns7:ModelSvc" xmlns:ns7="ModelSvc"/>
          </service>

          when in other client(command line run mode)
          Object result = server.invoke(oname, "getModelObj", opArgs, sig);
          can be write like this:
          //MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
          env.put(Context.PROVIDER_URL, "10.1.0.2");
          Context iniCtx = new InitialContext(env);
          RMIAdaptor server = (RMIAdaptor) iniCtx.lookup("jmx/rmi/RMIAdaptor");
          ModelObj result = (ModelObj)server.invoke(oname, "getModelObj", opArgs, sig);
          this will not throws java.llang.ClassCastException

          • 2. Re: how to get a user defined object invoked by mbeanserver
            mo momo Newbie

            Thank God!
            done!
            haha

            Hashtable env = new Hashtable();
             env.put("java.naming.factory.initial",
             "org.jboss.naming.HttpNamingContextFactory");
             env.put("java.naming.provider.url",
             "http://momo:8080/invoker/JNDIFactory");
             env.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");
             InitialContext ctx = new InitialContext(env); // From jndi.properties
             MBeanServerConnection server = (MBeanServerConnection) ctx
             .lookup("jmx/invoker/HttpAdaptor");