Search in sources :

Example 6 with OperationsException

use of javax.management.OperationsException in project tomcat by apache.

the class JMXProxyServlet method invokeOperationInternal.

/**
 * Invokes an operation on an MBean.
 *
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *            operation. They will be converted to the appropriate types to
 *            call the requested operation.
 * @return The value returned by the requested operation.
 */
// parameters can't be null if signature.length > 0
@SuppressWarnings("null")
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters) throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    int paramCount = null == parameters ? 0 : parameters.length;
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation, paramCount);
    if (null == methodInfo) {
        // getMethodInfo returns null for both "object not found" and "operation not found"
        MBeanInfo info = null;
        try {
            info = registry.getMBeanServer().getMBeanInfo(oname);
        } catch (InstanceNotFoundException infe) {
            throw infe;
        } catch (Exception e) {
            throw new IllegalArgumentException(sm.getString("jmxProxyServlet.noBeanFound", onameStr), e);
        }
        throw new IllegalArgumentException(sm.getString("jmxProxyServlet.noOperationOnBean", operation, Integer.valueOf(paramCount), onameStr, info.getClassName()));
    }
    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(), parameters[i]);
    }
    return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) OperationsException(javax.management.OperationsException) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

OperationsException (javax.management.OperationsException)6 IOException (java.io.IOException)3 MBeanException (javax.management.MBeanException)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 ServletException (jakarta.servlet.ServletException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 MBeanParameterInfo (javax.management.MBeanParameterInfo)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 AdminException (org.apache.geode.admin.AdminException)1