use of javax.management.RuntimeErrorException in project tomcat by apache.
the class BaseModelMBean method invoke.
/**
* Invoke a particular method on this MBean, and return any returned
* value.
*
* <p><strong>IMPLEMENTATION NOTE</strong> - This implementation will
* attempt to invoke this method on the MBean itself, or (if not
* available) on the managed resource object associated with this
* MBean.</p>
*
* @param name Name of the operation to be invoked
* @param params Array containing the method parameters of this operation
* @param signature Array containing the class names representing
* the signature of this operation
*
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking a method
*/
@Override
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException {
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).invoke(name, params, signature);
}
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Method name is null"), "Method name is null");
if (log.isDebugEnabled())
log.debug("Invoke " + name);
Method method = managedBean.getInvoke(name, params, signature, this, resource);
// Invoke the selected method on the appropriate object
Object result = null;
try {
if (method.getDeclaringClass().isAssignableFrom(this.getClass())) {
result = method.invoke(this, params);
} else {
result = method.invoke(resource, params);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
log.error("Exception invoking method " + name, t);
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException((Exception) t, "Exception invoking method " + name);
} catch (Exception e) {
log.error("Exception invoking method " + name, e);
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
use of javax.management.RuntimeErrorException in project tomcat by apache.
the class BaseModelMBean method getAttribute.
// key: operation val: invoke method
//private Hashtable invokeAttMap=new Hashtable();
/**
* Obtain and return the value of a specific attribute of this MBean.
*
* @param name Name of the requested attribute
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).getAttribute(name);
}
Method m = managedBean.getGetter(name, this, resource);
Object result = null;
try {
Class<?> declaring = m.getDeclaringClass();
// but this is the catalina class.
if (declaring.isAssignableFrom(this.getClass())) {
result = m.invoke(this, NO_ARGS_PARAM);
} else {
result = m.invoke(resource, NO_ARGS_PARAM);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException((Error) t, "Error invoking method " + name);
else
throw new MBeanException(e, "Exception invoking method " + name);
} catch (Exception e) {
throw new MBeanException(e, "Exception invoking method " + name);
}
// FIXME - should we validate the return type?
return (result);
}
use of javax.management.RuntimeErrorException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getMBeanInfo.
public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
// ------------------------------
// ------------------------------
DynamicMBean moi = getMBean(name);
final MBeanInfo mbi;
try {
mbi = moi.getMBeanInfo();
} catch (RuntimeMBeanException e) {
throw e;
} catch (RuntimeErrorException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeMBeanException(e, "getMBeanInfo threw RuntimeException");
} catch (Error e) {
throw new RuntimeErrorException(e, "getMBeanInfo threw Error");
}
if (mbi == null)
throw new JMRuntimeException("MBean " + name + "has no MBeanInfo");
checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");
return mbi;
}
use of javax.management.RuntimeErrorException in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method invokeMethod.
/*
* Invoke the given method, and throw the somewhat unpredictable
* appropriate exception if the method itself gets an exception.
*/
private Object invokeMethod(String opName, final Method method, final Object targetObject, final Object[] opArgs) throws MBeanException, ReflectionException {
try {
final Throwable[] caughtException = new Throwable[1];
AccessControlContext stack = AccessController.getContext();
Object rslt = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
ReflectUtil.checkPackageAccess(method.getDeclaringClass());
return MethodUtil.invoke(method, targetObject, opArgs);
} catch (InvocationTargetException e) {
caughtException[0] = e;
} catch (IllegalAccessException e) {
caughtException[0] = e;
}
return null;
}
}, stack, acc);
if (caughtException[0] != null) {
if (caughtException[0] instanceof Exception) {
throw (Exception) caughtException[0];
} else if (caughtException[0] instanceof Error) {
throw (Error) caughtException[0];
}
}
return rslt;
} catch (RuntimeErrorException ree) {
throw new RuntimeOperationsException(ree, "RuntimeException occurred in RequiredModelMBean " + "while trying to invoke operation " + opName);
} catch (RuntimeException re) {
throw new RuntimeOperationsException(re, "RuntimeException occurred in RequiredModelMBean " + "while trying to invoke operation " + opName);
} catch (IllegalAccessException iae) {
throw new ReflectionException(iae, "IllegalAccessException occurred in " + "RequiredModelMBean while trying to " + "invoke operation " + opName);
} catch (InvocationTargetException ite) {
Throwable mmbTargEx = ite.getTargetException();
if (mmbTargEx instanceof RuntimeException) {
throw new MBeanException((RuntimeException) mmbTargEx, "RuntimeException thrown in RequiredModelMBean " + "while trying to invoke operation " + opName);
} else if (mmbTargEx instanceof Error) {
throw new RuntimeErrorException((Error) mmbTargEx, "Error occurred in RequiredModelMBean while trying " + "to invoke operation " + opName);
} else if (mmbTargEx instanceof ReflectionException) {
throw (ReflectionException) mmbTargEx;
} else {
throw new MBeanException((Exception) mmbTargEx, "Exception thrown in RequiredModelMBean " + "while trying to invoke operation " + opName);
}
} catch (Error err) {
throw new RuntimeErrorException(err, "Error occurred in RequiredModelMBean while trying " + "to invoke operation " + opName);
} catch (Exception e) {
throw new ReflectionException(e, "Exception occurred in RequiredModelMBean while " + "trying to invoke operation " + opName);
}
}
use of javax.management.RuntimeErrorException in project geode by apache.
the class MX4JModelMBean method invokeMethod.
private Object invokeMethod(Object target, String methodName, Class[] params, Object[] args) throws MBeanException, ReflectionException {
// First try on this instance, then on the target
Object realTarget = null;
Method method = null;
try {
realTarget = this;
method = realTarget.getClass().getMethod(methodName, params);
} catch (NoSuchMethodException x) {
realTarget = target;
}
if (realTarget == null)
throw new MBeanException(new ServiceNotFoundException(LocalizedStrings.MX4JModelMBean_COULD_NOT_FIND_TARGET.toLocalizedString()));
if (method == null) {
try {
method = realTarget.getClass().getMethod(methodName, params);
} catch (NoSuchMethodException x) {
throw new ReflectionException(x);
}
}
try {
Object value = method.invoke(realTarget, args);
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.DEBUG))
logger.debug("Method invocation returned value: " + value);
return value;
} catch (IllegalAccessException x) {
throw new ReflectionException(x);
} catch (IllegalArgumentException x) {
throw new MBeanException(x);
} catch (InvocationTargetException x) {
Throwable t = x.getTargetException();
if (t instanceof Error)
throw new MBeanException(new RuntimeErrorException((Error) t));
else
throw new MBeanException((Exception) t);
}
}
Aggregations