1 Reply Latest reply on Jan 27, 2004 5:28 AM by Juha Lindfors

    RMI client to JMX service

    gjb Newbie

       

      "gjb9876" wrote:
      Hello.

      I have the following example:

      try
      {
      Hashtable env = new Hashtable();
      env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.provider.url", "localhost:1099");
      env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      InitialContext ctx = new InitialContext(env);
      RMIAdaptor server = (RMIAdaptor)ctx.lookup("jmx/rmi/RMIAdaptor");

      ObjectName objName = new ObjectName("nokia.ans:service=Xyzzy");
      String method = "getData";
      Object[] params = { new Integer(1), "testing" };
      String[] signature = { "java.lang.Integer", "java.lang.String" };

      Object result = server.invoke(objName, method, params, signature);
      System.out.println("result: " + result);

      if (result instanceof ANSDataIF)
      {
      System.out.println("yes, it is a ANSDataIF");
      if (result instanceof ANSPackageIF)
      {
      System.out.println("yes, it is a ANSPackageIF");
      ANSPackageIF pkg = (ANSPackageIF)result;
      System.out.println("desc: " + pkg.getDescription());
      }
      }

      }
      catch (Exception ex)
      {
      //System.out.println("EX: " + ex);
      ex.printStackTrace();
      }

      This code works great when the return value from my RMI call to getData returns a String. But now I've changed the return value to return an Object of data from my server, known as an ANSPackageIF datatype.

      I've included ans.jar on my classpath, which is where com.nokia.nes.ans.data.ANSPackage (class that implements ANSPackageIF) exists. However, I get the following exception...

      java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
      java.lang.ClassNotFoundException: com.nokia.nes.ans.data.ANSPackage (no security manager: RMI class loader disabled)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:169)
      at org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub.invoke(Unknown Source)
      at com.nokia.nes.orbit.DemoTest.tryJMX(DemoTest.java:162)
      at com.nokia.nes.orbit.DemoTest.main(DemoTest.java:53)
      Caused by: java.lang.ClassNotFoundException: com.nokia.nes.ans.data.ANSPackage (no security manager: RMI class loader disabled)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:368)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:159)
      at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:631)
      at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:257)
      at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:200)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1513)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)

      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
      at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:297)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:146)
      ... 3 more

      Exception occurs during the server.invoke() call.

      Does anyone have any ideas of how to get the RMIAdapter to find my classes to marshal? Do I need to generate some stubs, or something? Is my Object not defined correctly (it is Serializable already)...
      Thanks, Gretel