You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sc...@apache.org on 2020/01/08 14:57:49 UTC
[tomcat] 01/02: Fix
https://bz.apache.org/bugzilla/show_bug.cgi?id=58577
This is an automated email from the ASF dual-hosted git repository.
schultz pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 5ebf4101808a5b3267846aaae8f851b11eee72a2
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 | 8 ++++--
.../catalina/manager/LocalStrings.properties | 2 +-
java/org/apache/tomcat/util/modeler/Registry.java | 32 +++++++++++++++++++++-
webapps/docs/changelog.xml | 4 +++
4 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/java/org/apache/catalina/manager/JMXProxyServlet.java b/java/org/apache/catalina/manager/JMXProxyServlet.java
index 24cc809..a4ac8a8 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;
@@ -270,11 +271,12 @@ public class JMXProxyServlet extends HttpServlet {
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 76c7116..13b083b 100644
--- a/java/org/apache/catalina/manager/LocalStrings.properties
+++ b/java/org/apache/catalina/manager/LocalStrings.properties
@@ -168,5 +168,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 9b92a0c..2037684 100644
--- a/java/org/apache/tomcat/util/modeler/Registry.java
+++ b/java/org/apache/tomcat/util/modeler/Registry.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.List;
import javax.management.DynamicMBean;
+import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
@@ -328,7 +329,6 @@ public class Registry implements RegistryMBean, MBeanRegistration {
}
}
-
// -------------------- ID registry --------------------
/** Return an int ID for faster access. Will be used for notifications
@@ -512,6 +512,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 78baa1f..008d307 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -95,6 +95,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>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org