use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getAttribute.
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("Object name cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
}
if (attribute == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
}
name = nonDefaultDomain(name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "getAttribute", "Attribute = " + attribute + ", ObjectName = " + name);
}
final DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, attribute, name, "getAttribute");
try {
return instance.getAttribute(attribute);
} catch (AttributeNotFoundException e) {
throw e;
} catch (Throwable t) {
rethrowMaybeMBeanException(t);
// not reached
throw new AssertionError();
}
}
use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method setAttributes.
public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException {
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
if (attributes == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
name = nonDefaultDomain(name);
final DynamicMBean instance = getMBean(name);
final AttributeList allowedAttributes;
final SecurityManager sm = System.getSecurityManager();
if (sm == null)
allowedAttributes = attributes;
else {
String classname = getClassName(instance);
// Check if the caller has the right to invoke 'setAttribute'
//
checkMBeanPermission(classname, null, name, "setAttribute");
// Check if the caller has the right to invoke 'setAttribute'
// on each specific attribute
//
allowedAttributes = new AttributeList(attributes.size());
for (Attribute attribute : attributes.asList()) {
try {
checkMBeanPermission(classname, attribute.getName(), name, "setAttribute");
allowedAttributes.add(attribute);
} catch (SecurityException e) {
// OK: Do not add this attribute to the list
}
}
}
try {
return instance.setAttributes(allowedAttributes);
} catch (Throwable t) {
rethrow(t);
throw new AssertionError();
}
}
use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method createMBean.
private ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, boolean withDefaultLoaderRepository, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException {
Class<?> theClass;
if (className == null) {
final RuntimeException wrapped = new IllegalArgumentException("The class name cannot be null");
throw new RuntimeOperationsException(wrapped, "Exception occurred during MBean creation");
}
if (name != null) {
if (name.isPattern()) {
final RuntimeException wrapped = new IllegalArgumentException("Invalid name->" + name.toString());
final String msg = "Exception occurred during MBean creation";
throw new RuntimeOperationsException(wrapped, msg);
}
name = nonDefaultDomain(name);
}
checkMBeanPermission(className, null, null, "instantiate");
checkMBeanPermission(className, null, name, "registerMBean");
/* Load the appropriate class. */
if (withDefaultLoaderRepository) {
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "createMBean", "ClassName = " + className + ", ObjectName = " + name);
}
theClass = instantiator.findClassWithDefaultLoaderRepository(className);
} else if (loaderName == null) {
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "createMBean", "ClassName = " + className + ", ObjectName = " + name + ", Loader name = null");
}
theClass = instantiator.findClass(className, server.getClass().getClassLoader());
} else {
loaderName = nonDefaultDomain(loaderName);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "createMBean", "ClassName = " + className + ", ObjectName = " + name + ", Loader name = " + loaderName);
}
theClass = instantiator.findClass(className, loaderName);
}
checkMBeanTrustPermission(theClass);
// Check that the MBean can be instantiated by the MBeanServer.
Introspector.testCreation(theClass);
// Check the JMX MBean compliance of the class
Introspector.checkCompliance(theClass);
Object moi = instantiator.instantiate(theClass, params, signature, server.getClass().getClassLoader());
final String infoClassName = getNewMBeanClassName(moi);
return registerObject(infoClassName, moi, name);
}
use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getListener.
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException {
// ----------------
// Get listener object
// ----------------
DynamicMBean instance;
try {
instance = getMBean(listener);
} catch (InstanceNotFoundException e) {
throw EnvHelp.initCause(new ListenerNotFoundException(e.getMessage()), e);
}
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName());
final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName();
throw new RuntimeOperationsException(exc, msg);
}
return (NotificationListener) resource;
}
use of javax.management.RuntimeOperationsException in project jdk8u_jdk by JetBrains.
the class JmxMBeanServer method deserialize.
/**
* De-serializes a byte array in the context of a given MBean class loader.
* The class loader is the one that loaded the class with name "className".
*
* @param className The name of the class whose class loader should be
* used for the de-serialization.
* @param data The byte array to be de-sererialized.
*
* @return The de-serialized object stream.
*
* @exception OperationsException Any of the usual Input/Output
* related exceptions.
* @exception ReflectionException The specified class could not be
* loaded by the default loader repository
*
*/
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException {
if (className == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
}
/* Permission check */
// This call requires MBeanPermission 'getClassLoaderRepository'
final ClassLoaderRepository clr = getClassLoaderRepository();
Class<?> theClass;
try {
if (clr == null)
throw new ClassNotFoundException(className);
theClass = clr.loadClass(className);
} catch (ClassNotFoundException e) {
throw new ReflectionException(e, "The given class could not be " + "loaded by the default loader " + "repository");
}
return instantiator.deserialize(theClass.getClassLoader(), data);
}
Aggregations