Ragav Baskaran [
https://community.jboss.org/people/ragavendran_kb] created the discussion
"Info on Getting reference to JBoss MBean Server"
To view the discussion, visit:
https://community.jboss.org/message/749121#749121
--------------------------------------------------------------
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.
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/749121#749121]
Start a new discussion in Beginner's Corner at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]