Registering the MBean
Use
The last step in the registration of the resource MBean(s) is to call the following method:
mbs.registerMBean(mBeanObject, monitoringObjectName);
For more information about how you can use the registerMBean() method in different scenarios, see Registering MBeans .
Procedure
As the MBean server allows administrators only to work with it, you have to make sure that the code is executed with administrative rights. This is a common problem for the applications, because they are usually not executed with administrative rights. Therefore, if you do not use an explicit call to give administrative rights to the thread registering the resource MBean, you can declare a security role and map it to the administrators group. To do this, follow the steps below:
- Add a security role in the web.xml of a Servlet:
<security-role> <description>Role for accessing MBean server</description> <role-name>MBeanCreator</role-name> </security-role>
- Add the following lines to the Servlet's description to make the Servlet run using this role:
<run-as> <role-name>MBeanCreator</role-name> </run-as>
- Map the role declared in the web.xml to the AS Java "administrators" group.
This is done in the web-j2ee-engine.xml (situated in the /META-INF sub-folder of the WAR file):
<web-j2ee-engine> <security-role-map> <role-name> MBeanCreator </role-name> <server-role-name> administrators </server-role-name> </security-role-map> </web-j2ee-engine>
Next, see Sending Monitoring Data Actively Via JMX Notifications