2 Replies Latest reply on Jul 1, 2013 8:55 AM by Thiago Nascimento

    How to connect to mbean on remote jboss server

    dcwjboss Newbie

      I am not able to connect to remote jboss server (v5.1) from java standalone application acting as client.

      I already tried following but with no success:

      1) using JMXConnector:

                  String urlStr = "service:jmx:rmi://localhost/jndi/rmi://localhost:1090/jmxconnector";

                  // String urlStr = "service:jmx:remoting-jmx://localhost:4447";

                  JMXServiceURL url = new JMXServiceURL(urlStr);

                  conn = JMXConnectorFactory.connect(url, null);

                  MBeanServerConnection server = conn.getMBeanServerConnection();

      // getting java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection refused: connect] at JMXConnectorFactory.connect(..)

       

      2) using RMI :

              Hashtable table = new Hashtable();

              table.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");

              table.put(javax.naming.Context.PROVIDER_URL, "rmi://localhost:1099");

              InitialContext ctx = new InitialContext(table); // From table

              RMIAdaptor server = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");

      // getting javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: non-JRMP server at remote endpoint] while lookup.

       

      3) using Http :

              Hashtable table = new Hashtable();

              table.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");

              table.put(javax.naming.Context.PROVIDER_URL, "http://localhost:8080/invoker/JNDIFactory");

              table.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");

              InitialContext ctx = new InitialContext(table); // From table

              MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/HttpAdaptor");

      // getting javax.naming.NamingException: Failed to retrieve Naming interface for provider http://localhost:8080/invoker/JNDIFactory [Root exception is java.net.ProtocolException: Server redirected too many  times (20)] while creating InitialContext object.

       

      How to resolve above errors and What is the best way to connect to remote mbean server ?