// --------------------------------------------------------- Private Methods /// <exception cref="System.IO.IOException"/> private void ListBeans(JsonGenerator jg, ObjectName qry, string attribute, HttpServletResponse response) { Log.Debug("Listing beans for " + qry); ICollection <ObjectName> names = null; names = mBeanServer.QueryNames(qry, null); jg.WriteArrayFieldStart("beans"); IEnumerator <ObjectName> it = names.GetEnumerator(); while (it.HasNext()) { ObjectName oname = it.Next(); MBeanInfo minfo; string code = string.Empty; object attributeinfo = null; try { minfo = mBeanServer.GetMBeanInfo(oname); code = minfo.GetClassName(); string prs = string.Empty; try { if ("org.apache.commons.modeler.BaseModelMBean".Equals(code)) { prs = "modelerType"; code = (string)mBeanServer.GetAttribute(oname, prs); } if (attribute != null) { prs = attribute; attributeinfo = mBeanServer.GetAttribute(oname, prs); } } catch (AttributeNotFoundException e) { // If the modelerType attribute was not found, the class name is used // instead. Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (MBeanException e) { // The code inside the attribute getter threw an exception so log it, // and fall back on the class name Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (RuntimeException e) { // For some reason even with an MBeanException available to them // Runtime exceptionscan still find their way through, so treat them // the same as MBeanException Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e); } catch (ReflectionException e) { // This happens when the code inside the JMX bean (setter?? from the // java docs) threw an exception, so log it and fall back on the // class name Log.Error("getting attribute " + prs + " of " + oname + " threw an exception", e); } } catch (InstanceNotFoundException) { //Ignored for some reason the bean was not found so don't output it continue; } catch (IntrospectionException e) { // This is an internal error, something odd happened with reflection so // log it and don't output the bean. Log.Error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } catch (ReflectionException e) { // This happens when the code inside the JMX bean threw an exception, so // log it and don't output the bean. Log.Error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e); continue; } jg.WriteStartObject(); jg.WriteStringField("name", oname.ToString()); jg.WriteStringField("modelerType", code); if ((attribute != null) && (attributeinfo == null)) { jg.WriteStringField("result", "ERROR"); jg.WriteStringField("message", "No attribute with name " + attribute + " was found." ); jg.WriteEndObject(); jg.WriteEndArray(); jg.Close(); response.SetStatus(HttpServletResponse.ScNotFound); return; } if (attribute != null) { WriteAttribute(jg, attribute, attributeinfo); } else { MBeanAttributeInfo[] attrs = minfo.GetAttributes(); for (int i = 0; i < attrs.Length; i++) { WriteAttribute(jg, oname, attrs[i]); } } jg.WriteEndObject(); } jg.WriteEndArray(); }