3 Replies Latest reply on Aug 12, 2003 8:05 AM by Dmitry Namiot

    accessing MBean from a web page

    mrzeld Newbie


      i have been looking and looking and have yet to find a definitive example of how to access an MBean from a web page. do i have to implement the RMI interface to do this? is there not an easy way to access MBean's like there is for local EJB's?

      i have jboss 3.0.7 with tomcat. my MBean info is:
      Domain : com.jrw.jmx
      Name : com.jrw.jmx:service=TestJMX
      Class Name : com.jrw.jmx.TestJMX
      Description : Management Bean.

      the MBean has a variable in it (with get/set methods) called "value". i would like to be able to call getValue() from my web page(s).

      for right now, i am just running jboss on one server (no clustering or multiple servers, yet).

      any suggestions or www links with examples would be greatly appreciated. thanks.

        • 1. Re: accessing MBean from a web page

          Check the source for the jmx-console in cvs (under varia), its a servlet accessing MBeans. If you need to access MBeans from a different process then lookup the RMIAdaptor from the JNDI and use its interface to interact with MBeans

          • 2. Re: accessing MBean from a web page
            mrzeld Newbie

            just FYI,

            i just happen to have saved a PDF slide presentation from Sun on JMX. i was looking through it and found an example of what i needed. here is the code...

            <%@ page import="javax.management.*,java.util.*" %>


            //Step 1 - Get MBean server reference
            ArrayList servers = MBeanServerFactory.findMBeanServer(null);
            if (servers == null)
            throw new Exception("No MBeanServer found.");
            MBeanServer server = (MBeanServer)servers.get(0);
            //Step 2 - Create object to identify MBean
            ObjectName on = new ObjectName("com.jrw.jmx:service=TestJMX");
            //Step 3 - Update MBean Value attribute
            String newvalue = (String)request.getParameter("formValue");
            if (newvalue != null && newvalue.length() > 0)
            Attribute attribute = new Attribute("Value", newvalue);
            server.setAttribute( on, attribute );
            //Step 4 - Get latest Value attribute
            String value = (String)server.getAttribute( on,"Value");

            • 3. Re: accessing MBean from a web page
              Dmitry Namiot Newbie

              See for example JMX taglib from Coldtags suite: