2 Replies Latest reply on Nov 24, 2003 7:12 PM by Berlin Brown

    oh the newbie, mbean connection

    Berlin Brown Newbie

      I keep getting a service is not registered error. I am supposed to run this from an ejb or can I run this as a standalone program.

      public class ListServer {

      public static void main(String [] args) {

      System.out.println("Running program...");

      String _domain = "jboss";
      MBeanServer server = null;

      try {

      server = MBeanServerFactory.createMBeanServer(_domain);

      ArrayList svrs = MBeanServerFactory.findMBeanServer(null);

      Iterator iter = svrs.iterator();

      System.out.println("Running iter loop..." + svrs.size());

      while(iter.hasNext()) {

      MBeanServer svr = (MBeanServer)iter.next();

      String domain = svr.getDefaultDomain();

      System.out.println("X: " + domain);

      server = svr;

      } // end of the while

      ObjectName _obj = new ObjectName("jboss:service=Naming");

      MBeanInfo _info = server.getMBeanInfo(_obj);

      System.out.println("Class: " + _info.getClassName());


      } catch(Exception ex) {

      ex.printStackTrace();

      } // end of the try-catch


      } // end of the function main

      } // end of the class

        • 1. Re: oh the newbie, mbean connection
          Berlin Brown Newbie

          this is part of my build.xml

          And this code gives me a nullpointexception, I am using mbeandata from the htmladaptor

          org.jboss.jmx.adaptor.model.MBeanData

          MBeanData _data = (MBeanData)
          Server.getMBeanData("jboss:service=JNDIView");

















          • 2. Re: oh the newbie, mbean connection
            Berlin Brown Newbie

            SUPER newbie here, ok you have to run the code within the context of the application server as opposed to as standalone app.

            I will read next time, I swear it.

            Here is working code.

            package org.retro.gis;


            import java.net.*;
            import java.util.*;

            import javax.management.*;

            import javax.management.MBeanServer;

            import javax.servlet.*;
            import javax.servlet.http.*;

            import java.io.PrintWriter;
            import java.io.IOException;

            public class ListServer extends HttpServlet {


            public void init() throws ServletException
            {
            } // end of the function

            public void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException
            {

            response.setContentType("text/plain");

            // get a handle
            PrintWriter out = response.getWriter();

            out.println("");
            out.println("");
            out.println("Hello");


            goBean(out);


            out.println("");
            out.println("");

            } // end of the function

            private void goBean(PrintWriter _out) {

            String _domain = "jboss";
            MBeanServer server = null;

            try {

            server =
            (MBeanServer)MBeanServerFactory.findMBeanServer( null ).get( 0 );

            if (server == null)
            _out.println("Error, null");
            else
            _out.println("not null");

            String _s = server.getDefaultDomain();

            _out.println("X: " + _s);

            ObjectName name = new ObjectName("jboss:service=JNDIView");

            MBeanInfo info = server.getMBeanInfo(name);

            _out.println("Class: " + info.getClassName());

            } catch(Exception e) {

            //e.printStackTrace();
            _out.println("ERROR:" + e.getMessage());

            } // end of the try - catch

            } // end of the function

            } // end of the class