Currently one can only query Beans or set/get Attributes of them. It would be good if a certain operation of a MBean could be called by the Jmxproxy Servlet.
Got a specific patch in mind, or just a general "this would be good" feeling? ;)
It was definitely more than a feeling :) I'll attach a patch showing my modifications.
Created attachment 19340 [details] The patch introduces an invoke operation to the proxy The operation is specified by the "op" parameter and the parameters of the JMX operation are specified (as a comma seperated list) by the "ps" parameter.
This Tomcat 5 enhancement request has been moved to Tomcat 7 (the latest version) since Tomcat 5 development is limited and focussed on bugs and security issues whereas Tomcat 7 is still seeing new feature development.
After rather too long a variation of this patch has been applied to trunk and 7.0.x and will be included in 7.0.24 onwards. The main changes I made to the proposed patch were: - fixing a potential NPE when a method required zero parameters - improving the output when an array was returned (as is often the case with Tomcat MBeans)
Very useful feature and i'm just putting it onto our tomcat 6 boxes. However it doesn't account for the invocation of the mbean returning null when outputting the result. I propose that the invokeOperation becomes public void invokeOperation(PrintWriter writer, String onameStr, String op, String[] valuesStr){ try { ObjectName oname=new ObjectName( onameStr ); MBeanOperationInfo methodInfo = registry.getMethodInfo(oname,op); MBeanParameterInfo[] signature = methodInfo.getSignature(); String[] signatureTypes = new String[signature.length]; Object[] values = new Object[signature.length]; for (int i = 0; i < signature.length; i++) { MBeanParameterInfo pi = signature[i]; signatureTypes[i] = pi.getType(); values[i] = registry.convertValue(pi.getType(), valuesStr[i] ); } Object retVal = mBeanServer.invoke(oname,op,values,signatureTypes); if(retVal != null){ writer.println("OK - Operation " + op + " returned:"); output("", writer, retVal); }else{ writer.println("OK - Operation " + op + " without return value"); } } catch( Exception ex ) { writer.println("Error - " + ex.toString()); ex.printStackTrace(writer); } }
Created attachment 28173 [details] 2012-01-19_tc8_JMXProxyServlet.patch Yours covers most common use case of method returning void/null. I think null values inside arrays should be handled as well. I am attaching patch that I am thinking about that covers null values in getAttribute() operation as well.
Patch looks good to me. Applied to trunk and 7.0.x and will be included in 7.0.26 onwards.