0 Replies Latest reply on Jul 19, 2012 12:51 PM by Ragav Baskaran

    Info on Getting reference to JBoss MBean Server

    Ragav Baskaran Newbie

      Hi, I'm trying to get reference to Jboss MBean server using the code snippet below. I'm invoking this in a JSP file which is present in a WAR file and deployed in default profile of Jboss.

       

       

      If i try with the below,

      .....

      MBeanServer server = MBeanServerLocator.locateJBoss();

      .....

       

       

      I'm getting this error.

       

       

      [java] java.lang.IllegalStateException: No 'jboss' MBeanServer found!

      [java] at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:110)

      [java] at org.apache.jsp.demo_jsp._jspService(demo_jsp.java:67)

      [java] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

      [java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

      [java] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)

      [java] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)

      [java] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)

       

       

      If i use the below:

      ...

      MBeanServer server = MBeanServerLocator.locate();

      ...

       

      then getting this error.

       

      [java] java.util.NoSuchElementException

      [java] at java.util.AbstractList$Itr.next(AbstractList.java:350)

      [java] at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:67)

      [java] at org.jboss.mx.util.MBeanServerLocator.locate(MBeanServerLocator.java:80)

      [java] at org.apache.jsp.demo1_jsp._jspService(demo1_jsp.java:67)

      [java] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

      [java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

      [java] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)

       

       

      Also tried this option, but not able to get reference to the mbean server.

       

      .... 

      ArrayList serverList = MBeanServerFactory.findMBeanServer (null); 

      log ("servers.size() = " + serverList.size()); 

      ..... 

       

      Output:

      servers.size() = 0

       

      Can you please explain the reason for this error or what is the correct way to obtain reference of Jboss mbean server in application code running on the same VM.

       

       

       

      Dropped the below JSP file in to jmx-console.war of jboss

       

      <%@page import="javax.management.MBeanServer"%>

      <%@page import="org.jboss.mx.util.MBeanServerLocator"%>

      <%@page import="javax.management.MBeanServerFactory"%>

      <%@page import="java.util.ArrayList"%>

      <html>

      <body>

      <%

      MBeanServer server1 = MBeanServerLocator.locate();

      MBeanServer server2 = MBeanServerLocator.locateJBoss();

      ArrayList ser = MBeanServerFactory.findMBeanServer(null);

        %>

       

      Locate method          : <%=server1%>   </br>

      Locate Jboss method    : <%=server2%>   </br>

      findMBeanServer method : <%=ser%>   </br>

       

      </body>

      </html>

       

       

      I'm able to see the below output:

       

      Locate method : org.jboss.mx.server.MBeanServerImpl@121dcac[ defaultDomain='jboss' ]

      Locate Jboss method : org.jboss.mx.server.MBeanServerImpl@121dcac[ defaultDomain='jboss' ]

      findMBeanServer method : [org.jboss.mx.server.MBeanServerImpl@121dcac[ defaultDomain='jboss' ], org.jboss.mx.server.MBeanServerImpl@dc5c8b[ defaultDomain='null' ]]

       

      However if i drop the same JSP in to my application WAR and access it. I'm getting this exception as stated in my above post.

       

       

      I'm running out of clues. Any help will be highly appreciated.