Search in sources :

Example 36 with RuntimeOperationsException

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();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 37 with RuntimeOperationsException

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();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 38 with RuntimeOperationsException

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);
}
Also used : JMRuntimeException(javax.management.JMRuntimeException) NamedObject(com.sun.jmx.mbeanserver.NamedObject) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 39 with RuntimeOperationsException

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;
}
Also used : DynamicMBean(javax.management.DynamicMBean) JMRuntimeException(javax.management.JMRuntimeException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ListenerNotFoundException(javax.management.ListenerNotFoundException) NamedObject(com.sun.jmx.mbeanserver.NamedObject) NotificationListener(javax.management.NotificationListener) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 40 with RuntimeOperationsException

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);
}
Also used : ClassLoaderRepository(javax.management.loading.ClassLoaderRepository) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

RuntimeOperationsException (javax.management.RuntimeOperationsException)68 AttributeNotFoundException (javax.management.AttributeNotFoundException)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)21 ReflectionException (javax.management.ReflectionException)20 MBeanException (javax.management.MBeanException)19 Descriptor (javax.management.Descriptor)17 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 ListenerNotFoundException (javax.management.ListenerNotFoundException)16 RuntimeErrorException (javax.management.RuntimeErrorException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 ServiceNotFoundException (javax.management.ServiceNotFoundException)13 DynamicMBean (javax.management.DynamicMBean)10 FileLogger (mx4j.log.FileLogger)10 Logger (mx4j.log.Logger)10 MBeanLogger (mx4j.log.MBeanLogger)10 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)9 JMRuntimeException (javax.management.JMRuntimeException)8 Attribute (javax.management.Attribute)7 MalformedObjectNameException (javax.management.MalformedObjectNameException)7