Bug 38216 - Extend Jmxproxy to allow call of MBean Operations
Summary: Extend Jmxproxy to allow call of MBean Operations
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Manager (show other bugs)
Version: unspecified
Hardware: Other other
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-10 18:01 UTC by Christopher Hlubek
Modified: 2012-01-22 18:34 UTC (History)
0 users



Attachments
The patch introduces an invoke operation to the proxy (2.47 KB, patch)
2007-01-02 06:59 UTC, Christopher Hlubek
Details | Diff
2012-01-19_tc8_JMXProxyServlet.patch (1.97 KB, patch)
2012-01-19 07:19 UTC, Konstantin Kolinko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Hlubek 2006-01-10 18:01:22 UTC
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.
Comment 1 Yoav Shapira 2006-12-24 17:52:21 UTC
Got a specific patch in mind, or just a general "this would be good" feeling? ;)
Comment 2 Christopher Hlubek 2007-01-02 04:25:39 UTC
It was definitely more than a feeling :)

I'll attach a patch showing my modifications.
Comment 3 Christopher Hlubek 2007-01-02 06:59:48 UTC
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.
Comment 4 Mark Thomas 2011-12-20 20:32:18 UTC
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.
Comment 5 Mark Thomas 2012-01-15 21:42:53 UTC
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)
Comment 6 Chris O'Connor 2012-01-17 14:49:57 UTC
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);
        }
    }
Comment 7 Konstantin Kolinko 2012-01-19 07:19:33 UTC
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.
Comment 8 Mark Thomas 2012-01-22 18:34:10 UTC
Patch looks good to me. Applied to trunk and 7.0.x and will be included in 7.0.26 onwards.