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

    Remote MBean access

    n_ton

      Hi,

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

      http://wiki.jboss.org/wiki/Wiki.jsp?page=JNDIClientConfiguration

      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://10.0.0.3:1099");
      
       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: 127.0.0.1; 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.

      Norton

        • 1. Re: Remote MBean access
          n_ton

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

          http://wiki.jboss.org/wiki/Wiki.jsp?page=UsingJBossBehindAFirewall

          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.

          Norton

          • 2. Re: Remote MBean access
            n_ton

            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);
             server.invoke(...);


            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.

            Norton


            • 3. Re: Remote MBean access
              starksm64

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