Author: schultz
Date: Thu Feb  2 22:46:38 2012
New Revision: 1239899

URL: http://svn.apache.org/viewvc?rev=1239899&view=rev
Log:
Added support to the JMXProxyServlet for fetching a specific key from a 
CompositeData value.
Added documentation for the entire 'get' command for the JMXProxyServlet, 
including the new optional 'key' parameter.


Modified:
    tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
    tomcat/trunk/webapps/docs/manager-howto.xml

Modified: tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java?rev=1239899&r1=1239898&r2=1239899&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java Thu Feb  
2 22:46:38 2012
@@ -25,6 +25,7 @@ import javax.management.MBeanOperationIn
 import javax.management.MBeanParameterInfo;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -97,7 +98,7 @@ public class JMXProxyServlet extends Htt
         qry=request.getParameter("get");
         if( qry!= null ) {
             String name=request.getParameter("att");
-            getAttribute( writer, qry, name );
+            getAttribute( writer, qry, name, request.getParameter("key") );
             return;
         }
         qry = request.getParameter("invoke");
@@ -122,18 +123,35 @@ public class JMXProxyServlet extends Htt
 
     }
 
-    public void getAttribute(PrintWriter writer, String onameStr, String att) {
+    public void getAttribute(PrintWriter writer, String onameStr, String att, 
String key) {
         try {
             ObjectName oname = new ObjectName(onameStr);
             Object value = mBeanServer.getAttribute(oname, att);
+
+            if(null != key && value instanceof CompositeData)
+              value = ((CompositeData)value).get(key);
+
             String valueStr;
             if (value != null) {
                 valueStr = value.toString();
             } else {
                 valueStr = "<null>";
             }
-            writer.println("OK - Attribute get '" + onameStr + "' - " + att
-                    + "= " + MBeanDumper.escape(valueStr));
+
+            writer.print("OK - Attribute get '");
+            writer.print(onameStr);
+            writer.print("' - ");
+            writer.print(att);
+
+            if(null != key) {
+                writer.print(" - key '");
+                writer.print(key);
+                writer.print("'");
+            }
+
+            writer.print(" = ");
+
+            writer.println(MBeanDumper.escape(valueStr));
         } catch (Exception ex) {
             writer.println("Error - " + ex.toString());
             ex.printStackTrace(writer);

Modified: tomcat/trunk/webapps/docs/manager-howto.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/manager-howto.xml?rev=1239899&r1=1239898&r2=1239899&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/manager-howto.xml (original)
+++ tomcat/trunk/webapps/docs/manager-howto.xml Thu Feb  2 22:46:38 2012
@@ -1265,6 +1265,37 @@ http://webserver/manager/jmxproxy/?qry=S
     you may run.
   </subsection>
 
+  <subsection name="JMX Get command">
+    The JXMProxyServlet also supports a "get" command that you can use to
+    fetch the value of a specific MBean's attribute. The general form of
+    the <code>get</code> command is:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=BEANNAME&amp;att=MYATTRIBUTE&amp;key=MYKEY
+    </source>
+
+    You must provide the following parameters:
+    <ol>
+      <li><code>get</code>: The full bean name</li>
+      <li><code>att</code>: The attribute you wish to fetch</li>
+      <li><code>key</code>: (optional) The key into a CompositeData MBean 
attribute</li>
+    </ol>
+
+    If all goes well, then it will say OK, otherwise an error message will
+    be shown. For example, let's say we wish to fetch the current heap memory
+    data:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage
+    </source>
+
+    Or, if you only want the "used" key:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage&amp;key=used
+    </source>
+  </subsection>
+
   <subsection name="JMX Set command">
     Now that you can query an MBean, its time to muck with Tomcat's internals!
     The general form of the set command is :



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to