Obtaining a Reference to SipServletSnmpTrapRuntimeMBean
Any SIP Servlet that generates SNMP traps must first obtain a reference to the SipServletSnmpTrapRuntimeMBean. Example 16-2 shows the sample code for a method to obtain the MBean.
Example 16-2 Sample Method for Accessing SipServletSnmpTrapRuntimeMBean
public SipServletSnmpTrapRuntimeMBean getServletSnmpTrapRuntimeMBean() {
MBeanHome localHomeB = null;
SipServletSnmpTrapRuntimeMBean ssTrapMB = null;
try
{
Context ctx = new InitialContext();
localHomeB = (MBeanHome)ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
ctx.close();
} catch (NamingException ne){
ne.printStackTrace();
}
Set set = localHomeB.getMBeansByType("SipServletSnmpTrapRuntime");
if (set == null || set.isEmpty()) {
try {
throw new ServletException("Unable to lookup type
'SipServletSnmpTrapRuntime'");
} catch (ServletException e) {
e.printStackTrace();
}
}
ssTrapMB = (SipServletSnmpTrapRuntimeMBean) set.iterator().next();
return ssTrapMB;
}