Author: schultz
Date: Thu Sep 6 15:08:58 2012
New Revision: 1381635
URL: http://svn.apache.org/viewvc?rev=1381635&view=rev
Log:
Added multi-op modes to JMXProxyServlet.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1381633
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java?rev=1381635&r1=1381634&r2=1381635&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
Thu Sep 6 15:08:58 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;
+ // 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("get");
- if( qry!= null ) {
- String name=request.getParameter("att");
- getAttribute( writer, qry, name, request.getParameter("key") );
- 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("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 = "*:*";
+ // 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/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1381635&r1=1381634&r2=1381635&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Sep 6 15:08:58 2012
@@ -64,6 +64,11 @@
<bug>53828</bug>: Use correct status code when closing a WebSocket
connection normally in response to a close frame from a client. (markt)
</fix>
+ <update>
+ <code>JMXProxyServlet</code> now allows multi-op commands like
+ <code>invokeAndSet</code>code>, <code>invokeAndGet</code>,
+ etc. (schultz)
+ </update>
</changelog>
</subsection>
<subsection name="Jasper">
Modified: tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml?rev=1381635&r1=1381634&r2=1381635&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml Thu Sep 6 15:08:58 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&invoke=BEANNAME&op=METHODNAME&ps=COMMASEPARATEDPARAMETERS&set=BEANNAME&att=MYATTRIBUTE&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&invoke=BEANNAME&op=METHODNAME&ps=COMMASEPARATEDPARAMETERS&get=BEANNAME&att=MYATTRIBUTE[&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&invoke=BEANNAME&op=METHODNAME&ps=COMMASEPARATEDPARAMETERS&get=BEANNAME&att=MYATTRIBUTE[&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&invoke=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&op=resetCounters&get=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&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&get=BEANNAME&att=MYATTRIBUTE[&key=MYKEY
(optional)]&set=BEANNAME&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&get=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&att=maxTime&set=Catalina:type=GlobalRequestProcessor,name="http-nio-127.0.0.1-8080"&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: [email protected]
For additional commands, e-mail: [email protected]