3 Replies Latest reply on Mar 12, 2006 11:10 AM by Scott Stark

    Remote MBean access

    Norton Newbie


      I am trying to access an MBean from a remote client. From the wiki page:


      I was told to replace 'localhost' with my IP address to get an InitialContext connected to my JBoss server. So here's what I did in my code:

      Properties props = new Properties();
       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "jnp://");
       InitialContext ic = new InitialContext(props);
       RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");

      but I get the following error when the lookup() is executed:

      javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host:; nested exception is:
      java.net.ConnectException: Connection refused: connect]

      Did I do something wrong? Why is it still trying to connect to localhost?

      Thanx for your help.


        • 1. Re: Remote MBean access
          Norton Newbie

          After some more searching, I found a posting that referred to:


          I was able to complete the instructions at the bottom of that page that fixed my previous problem, but now I am getting:

          java.lang.ClassCastException: org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub

          From my remote client. I run the same client on the same machine the server is running and it works fine. Should I be casting to RMIAdaptorImpl_Stub instead of RMIAdaptor? Are there any implications to doing this?

          Thanx in advance.


          • 2. Re: Remote MBean access
            Norton Newbie

            So here's what I've done:

            I have JBoss 3.0.8 running on RedHat 7.3 with JDK 1.4.2_10. I have a client that connects to JBoss with the following code:

            Properties props = new Properties();
             props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
             props.put(Context.PROVIDER_URL, "jnp://yeager:1099");
             System.out.println("In remote call");
             InitialContext ic = new InitialContext(props);
             System.out.println("ic: " + ic);
             Object obj = ic.lookup("jmx/rmi/RMIAdaptor");
             System.out.println("obj: " + obj.getClass().getName());
             org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub server = ( org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub) obj;
             System.out.println("server: " + server);
             ObjectName objName = new ObjectName("jboss.j2ee:jndiName=" + name + ",service=EJB");
             System.out.println("objName: " + objName);

            When the client runs on the same box as the JBoss server, everything works fine. When I move the client to a Windows XP box running JDK 1.4.2_10, I get the following output that ends in a ClassCastException:

            In remote call
            ic: javax.naming.InitialContext@187d27e
            obj: org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl_Stub

            As you can see, the object coming back from the InitialContext is an RMIAdaptorImpl_Stub and that's what I cast it to, but I still get the ClassCastException.

            What's going on here?

            Thanx in advance.


            • 3. Re: Remote MBean access
              Scott Stark Master

              Try using a more recent jboss version, 4.0.3SP1, 3.2.8SP1 are the latest.