1 Reply Latest reply on Aug 9, 2006 6:30 AM by mo momo

    how to get a user definition object invoked by mbeanserver

    mo momo Newbie

      I want to get an object defined by me through mbean in web service

      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) {
       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"/>

      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.PROVIDER_URL, "");
      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