Summary: | Extend Jmxproxy to allow call of MBean Operations | ||
---|---|---|---|
Product: | Tomcat 7 | Reporter: | Christopher Hlubek <hlubek> |
Component: | Manager | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | ||
Priority: | P2 | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Hardware: | Other | ||
OS: | other | ||
Attachments: |
The patch introduces an invoke operation to the proxy
2012-01-19_tc8_JMXProxyServlet.patch |
Description
Christopher Hlubek
2006-01-10 18:01:22 UTC
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. |