This is an automated email from the ASF dual-hosted git repository.

schultz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 7fc6d5a  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58577
7fc6d5a is described below

commit 7fc6d5ae83f7063fb543a1900285094f998bcd87
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Wed Jan 8 09:53:52 2020 -0500

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58577
    
    Respect the number of arguments when searching for a method to invoke.
---
 .../apache/catalina/manager/JMXProxyServlet.java   | 10 ++++---
 .../catalina/manager/LocalStrings.properties       |  2 +-
 java/org/apache/tomcat/util/modeler/Registry.java  | 32 +++++++++++++++++++++-
 webapps/docs/changelog.xml                         |  4 +++
 4 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/catalina/manager/JMXProxyServlet.java 
b/java/org/apache/catalina/manager/JMXProxyServlet.java
index e4cdf8e..30b718e 100644
--- a/java/org/apache/catalina/manager/JMXProxyServlet.java
+++ b/java/org/apache/catalina/manager/JMXProxyServlet.java
@@ -21,6 +21,7 @@ import java.io.PrintWriter;
 import java.util.Set;
 
 import javax.management.Attribute;
+import javax.management.InstanceNotFoundException;
 import javax.management.MBeanException;
 import javax.management.MBeanInfo;
 import javax.management.MBeanOperationInfo;
@@ -264,17 +265,18 @@ public class JMXProxyServlet extends HttpServlet {
     private Object invokeOperationInternal(String onameStr, String operation, 
String[] parameters)
             throws OperationsException, MBeanException, ReflectionException {
         ObjectName oname = new ObjectName(onameStr);
-        MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, 
operation);
+        MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, 
operation, (null == parameters ? 0 : parameters.length));
         if(null == methodInfo) {
             // getMethodInfo returns null for both "object not found" and 
"operation not found"
             MBeanInfo info = null;
             try {
                 info = registry.getMBeanServer().getMBeanInfo(oname);
-
-                throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noOperationOnBean", 
operation, onameStr, info.getClassName()));
+            } catch (InstanceNotFoundException infe) {
+                throw infe;
             } catch (Exception e) {
-                throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noBeanFound", onameStr));
+                throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noBeanFound", onameStr), 
e);
             }
+            throw new 
IllegalArgumentException(sm.getString("jmxProxyServlet.noOperationOnBean", 
operation, (null == parameters ? 0 : parameters.length), onameStr, 
info.getClassName()));
         }
 
         MBeanParameterInfo[] signature = methodInfo.getSignature();
diff --git a/java/org/apache/catalina/manager/LocalStrings.properties 
b/java/org/apache/catalina/manager/LocalStrings.properties
index 51acc29..afc1fec 100644
--- a/java/org/apache/catalina/manager/LocalStrings.properties
+++ b/java/org/apache/catalina/manager/LocalStrings.properties
@@ -193,5 +193,5 @@ managerServlet.vminfo=OK - VM info
 statusServlet.complete=Complete Server Status
 statusServlet.title=Server Status
 
-jmxProxyServlet.noOperationOnBean=Cannot find operation [{0}] on object name 
[{1}], which is a [{2}]
+jmxProxyServlet.noOperationOnBean=Cannot find operation [{0}] with [{1}] 
arguments on object name [{2}], which is a [{3}]
 jmxProxyServlet.noBeanFound=Cannot find MBean with object name [{0}]
diff --git a/java/org/apache/tomcat/util/modeler/Registry.java 
b/java/org/apache/tomcat/util/modeler/Registry.java
index b38af7a..41d24b7 100644
--- a/java/org/apache/tomcat/util/modeler/Registry.java
+++ b/java/org/apache/tomcat/util/modeler/Registry.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.management.DynamicMBean;
+import javax.management.InstanceNotFoundException;
 import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanInfo;
 import javax.management.MBeanOperationInfo;
@@ -263,7 +264,6 @@ public class Registry implements RegistryMBean, 
MBeanRegistration {
         }
     }
 
-
     // -------------------- ID registry --------------------
 
     /**
@@ -397,6 +397,36 @@ public class Registry implements RegistryMBean, 
MBeanRegistration {
         return null;
     }
 
+    /**
+     * Find the operation info for a method.
+     *
+     * @param oname The bean name
+     * @param opName The operation name
+     * @param argCount The number of arguments to the method
+     * @return the operation info for the specified operation
+     * @throws InstanceNotFoundException If the object name is not bound to an 
MBean
+     */
+    public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName, 
int argCount)
+        throws InstanceNotFoundException
+    {
+        MBeanInfo info = null;
+        try {
+            info = getMBeanServer().getMBeanInfo(oname);
+        } catch (InstanceNotFoundException infe) {
+            throw infe;
+        } catch (Exception e) {
+            log.warn(sm.getString("registry.noMetadata", oname), e);
+            return null;
+        }
+        MBeanOperationInfo attInfo[] = info.getOperations();
+        for (int i = 0; i < attInfo.length; i++) {
+            if (opName.equals(attInfo[i].getName())
+                && argCount == attInfo[i].getSignature().length) {
+                return attInfo[i];
+            }
+        }
+        return null;
+    }
 
     /**
      * Unregister a component. This is just a helper that avoids exceptions by
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index bf6ce4a..2e3a7cc 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -92,6 +92,10 @@
         Do not throw a NullPointerException when an MBean or operation cannot
         be found by the JMXProxyServlet. (schultz)
       </fix>
+      <fix>
+        <bug>58577</bug>: Respect the argument-count when searching for MBean
+        operations to invoke via the JMXProxyServlet.
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to