Author: schultz
Date: Thu Sep  6 15:02:42 2012
New Revision: 1381633

URL: http://svn.apache.org/viewvc?rev=1381633&view=rev
Log:
Added multi-op modes to JMXProxyServlet.

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=1381633&r1=1381632&r2=1381633&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java Thu Sep  
6 15:02:42 2012
@@ -93,33 +93,98 @@ public class JMXProxyServlet extends Htt
             return;
         }
 
-        String qry=request.getParameter("set");
-        if( qry!= null ) {
-            String name=request.getParameter("att");
-            String val=request.getParameter("val");
-
-            setAttribute( writer, qry, name, val );
-            return;
-        }
-        qry=request.getParameter("get");
-        if( qry!= null ) {
-            String name=request.getParameter("att");
-            getAttribute( writer, qry, name, request.getParameter("key") );
-            return;
+        // Invoke an operation, then execute a "get"
+        if(null != request.getParameter("invokeAndGet")) {
+            try {
+                invokeOperationInternal(request.getParameter("invoke"),
+                                        request.getParameter("op"),
+                                        
getInvokeParameters(request.getParameter("ps")));
+
+                getAttribute(writer,
+                             request.getParameter("get"),
+                             request.getParameter("att"),
+                             request.getParameter("key"));
+            } catch (Exception e) {
+                writer.println("Error - " + e.toString());
+                e.printStackTrace(writer);
+            }
         }
-        qry = request.getParameter("invoke");
-        if(qry != null) {
-            String opName=request.getParameter("op");
-            String[] params = getInvokeParameters(request.getParameter("ps"));
-            invokeOperation(writer, qry, opName, params);
-            return;
+        // Get a value first, then invoke an operation
+        else if(null != request.getParameter("getAndInvoke")) {
+            try {
+                getAttribute(writer,
+                             request.getParameter("get"),
+                             request.getParameter("att"),
+                             request.getParameter("key"));
+
+                invokeOperationInternal(request.getParameter("invoke"),
+                                        request.getParameter("op"),
+                                        
getInvokeParameters(request.getParameter("ps")));
+            } catch (Exception e) {
+                writer.println("Error - " + e.toString());
+                e.printStackTrace(writer);
+            }
         }
-        qry=request.getParameter("qry");
-        if( qry == null ) {
-            qry = "*:*";
+        // Invoke an operation, then set a value
+        else if(null != request.getParameter("invokeAndSet")) {
+            try {
+                invokeOperationInternal(request.getParameter("invoke"),
+                                        request.getParameter("op"),
+                                        
getInvokeParameters(request.getParameter("ps")));
+
+                setAttribute(writer,
+                             request.getParameter("set"),
+                             request.getParameter("att"),
+                             request.getParameter("val"));
+            } catch (Exception e) {
+                writer.println("Error - " + e.toString());
+                e.printStackTrace(writer);
+            }
         }
+        // Get a value, then set its value
+        else if(null != request.getParameter("getAndSet")) {
+            try {
+                getAttribute(writer,
+                             request.getParameter("get"),
+                             request.getParameter("att"),
+                             request.getParameter("key"));
+
+                setAttributeInternal(request.getParameter("set"),
+                                     request.getParameter("att"),
+                                     request.getParameter("val"));
+            } catch (Exception e) {
+                writer.println("Error - " + e.toString());
+                e.printStackTrace(writer);
+            }
+        } else {
+            String qry=request.getParameter("set");
+            if( qry!= null ) {
+                String name=request.getParameter("att");
+                String val=request.getParameter("val");
+
+                setAttribute( writer, qry, name, val );
+                return;
+            }
+            qry=request.getParameter("get");
+            if( qry!= null ) {
+                String name=request.getParameter("att");
+                getAttribute( writer, qry, name, request.getParameter("key") );
+                return;
+            }
+            qry = request.getParameter("invoke");
+            if(qry != null) {
+                String opName=request.getParameter("op");
+                String[] params = 
getInvokeParameters(request.getParameter("ps"));
+                invokeOperation(writer, qry, opName, params);
+                return;
+            }
+            qry=request.getParameter("qry");
+            if( qry == null ) {
+                qry = "*:*";
+            }
 
-        listBeans( writer, qry );
+            listBeans( writer, qry );
+        }
     }
 
     public void getAttribute(PrintWriter writer, String onameStr, String att, 
String key) {

Modified: tomcat/trunk/webapps/docs/manager-howto.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/manager-howto.xml?rev=1381633&r1=1381632&r2=1381633&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/manager-howto.xml (original)
+++ tomcat/trunk/webapps/docs/manager-howto.xml Thu Sep  6 15:02:42 2012
@@ -1344,7 +1344,98 @@ http://webserver/manager/jmxproxy/?invok
 
http://localhost:8080/manager/jmxproxy/?invoke=Catalina%3Atype%3DService&op=findConnectors&ps=
 </source>
   </subsection>
-
+  <subsection name="Multiple operations" anchor="multiOp">
+    <p>
+      The JMXProxyServlet can also perform certain combinations of
+      operations with a single HTTP request:
+    </p>
+    <ul>
+      <li><code>invoke</code> and <code>set</code></li>
+      <li><code>invoke</code> and <code>get</code></li>
+      <li><code>get</code> and <code>invoke</code></li>
+      <li><code>get</code> and <code>set</code></li>
+    </ul>
+  <subsection name="Invoke and set" anchor="invokeAndSet">
+    <p>
+      If you want to invoke an operation and then set a value, add an
+      <code>invokeAndSet</code> parameter to the request and make sure you
+      have all the required parameters for both the <code>invoke</code>
+      and <code>set</code> commands:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy/?invokeAndSet&amp;invoke=BEANNAME&amp;op=METHODNAME&amp;ps=COMMASEPARATEDPARAMETERS&amp;set=BEANNAME&amp;att=MYATTRIBUTE&amp;val=NEWVALUE
+    </source>
+    <p>
+      Note that you can use different target MBeans if you want to, because
+      the <code>invoke</code> and <code>set</code> parameters can obviously
+      have different values. 
+    </p>
+  </subsection>
+  <subsection name="Invoke and get" anchor="invokeAndGet">
+    <p>
+      If you want to invoke an operation and then get a value, add an
+      <code>invokeAndGet</code> parameter to the request and make sure you
+      have all the required parameters for both the <code>invoke</code>
+      and <code>get</code> commands:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy/?invokeAndGet&amp;invoke=BEANNAME&amp;op=METHODNAME&amp;ps=COMMASEPARATEDPARAMETERS&amp;get=BEANNAME&amp;att=MYATTRIBUTE[&amp;key=MYKEY
 (optional)]
+    </source>
+    <p>
+      Note that you can use different target MBeans if you want to, because
+      the <code>invoke</code> and <code>get</code> parameters can obviously
+      have different values. 
+    </p>
+  </subsection>
+  <subsection name="Get and invoke" anchor="getAndInvoke">
+    <p>
+      If you want to get a value and then invoke an operation, add a
+      <code>getAndInvoke</code> parameter to the request and make sure you
+      have all the required parameters for both the <code>invoke</code>
+      and <code>get</code> commands:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy/?getAndInvoke&amp;invoke=BEANNAME&amp;op=METHODNAME&amp;ps=COMMASEPARATEDPARAMETERS&amp;get=BEANNAME&amp;att=MYATTRIBUTE[&amp;key=MYKEY
 (optional)]
+    </source>
+    <p>
+      Here is an example of how to get the current value of a request
+      processor's "maxTime" metric and then reset all the metrics counters:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy?getAndInvoke&amp;invoke=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&amp;op=resetCounters&amp;get=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&amp;att=maxTime
+    </source>
+    <p>
+      Note that you can use different target MBeans if you want to, because
+      the <code>invoke</code> and <code>get</code> parameters can obviously
+      have different values. 
+    </p>
+  </subsection>
+  <subsection name="Get and set" anchor="getAndSet">
+    <p>
+      If you want to get a value and then set a value, add a
+      <code>getAndSet</code> parameter to the request and make sure you
+      have all the required parameters for both the <code>get</code>
+      and <code>set</code> commands:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy/?getAndSet&amp;get=BEANNAME&amp;att=MYATTRIBUTE[&amp;key=MYKEY
 (optional)]&amp;set=BEANNAME&amp;val=NEWVALUE
+    </source>
+    <p>
+      Here is an example of how to get the current value of a request
+      processor's "maxTime" metric and then set that value to 0:
+    </p>
+    <source>
+http://webserver/manager/jmxproxy?getAndSet&amp;get=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&amp;att=maxTime&amp;set=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&amp;val=0
+    </source>
+    <p>
+      Note that you can use different target MBeans if you want to, because
+      the <code>invoke</code> and <code>get</code> parameters can obviously
+      have different values, <b>but you must use the same attribtue name for
+      both</b> because both the <code>get</code> and <code>set</code> commands
+      both use the <code>att</code> parameter to identify the MBean attribute.
+    </p>
+  </subsection>
+  </subsection>
 </section>
 
 



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

Reply via email to