Search in sources :

Example 31 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class AbstractDynamicMBean method setAttributes.

/**
 * Sets the manageable attributes, as specified by the DynamicMBean interface.
 */
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList list = new AttributeList();
    if (attributes != null) {
        for (int i = 0; i < attributes.size(); ++i) {
            Attribute attribute = (Attribute) attributes.get(i);
            try {
                setAttribute(attribute);
                list.add(attribute);
            } catch (AttributeNotFoundException ignored) {
            } catch (InvalidAttributeValueException ignored) {
            } catch (MBeanException ignored) {
            } catch (ReflectionException ignored) {
            }
        }
    }
    return list;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 32 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class AbstractDynamicMBean method invoke.

/**
 * Looks up the method to call on given resource and invokes it.
 * The default implementation requires that the methods that implement attribute and operation behavior
 * on the resource object are public, but it is possible to override this behavior, and call
 * also private methods.
 * @see #findMethod
 * @see #invokeMethod
 */
protected Object invoke(Object resource, String name, Class[] params, Object[] args) throws InvalidAttributeValueException, MBeanException, ReflectionException {
    try {
        Class cls = resource.getClass();
        Method method = findMethod(cls, name, params);
        return invokeMethod(method, resource, args);
    } catch (NoSuchMethodException x) {
        throw new ReflectionException(x);
    } catch (IllegalAccessException x) {
        throw new ReflectionException(x);
    } catch (IllegalArgumentException x) {
        throw new InvalidAttributeValueException(x.toString());
    } catch (InvocationTargetException x) {
        Throwable t = x.getTargetException();
        if (t instanceof RuntimeException)
            throw new RuntimeMBeanException((RuntimeException) t);
        else if (t instanceof Exception)
            throw new MBeanException((Exception) t);
        throw new RuntimeErrorException((Error) t);
    }
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) Method(java.lang.reflect.Method) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) RuntimeMBeanException(javax.management.RuntimeMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) ReflectionException(javax.management.ReflectionException) RuntimeMBeanException(javax.management.RuntimeMBeanException) MBeanException(javax.management.MBeanException)

Example 33 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project felix by apache.

the class AbstractDynamicMBean method getAttribute.

/**
 * Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
 * @see #createMBeanAttributeInfo
 */
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (attribute == null)
        throw new AttributeNotFoundException("Attribute " + attribute + " not found");
    Object resource = null;
    MBeanInfo info = null;
    synchronized (this) {
        resource = getResourceOrThis();
        info = getMBeanInfo();
    }
    MBeanAttributeInfo[] attrs = info.getAttributes();
    if (attrs == null || attrs.length == 0)
        throw new AttributeNotFoundException("No attributes defined for this MBean");
    for (int i = 0; i < attrs.length; ++i) {
        MBeanAttributeInfo attr = attrs[i];
        if (attr == null)
            continue;
        if (attribute.equals(attr.getName())) {
            if (!attr.isReadable())
                throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
            // Found, invoke via reflection
            String prefix = null;
            if (attr.isIs())
                prefix = "is";
            else
                prefix = "get";
            try {
                return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
            } catch (InvalidAttributeValueException x) {
                throw new ReflectionException(x);
            }
        }
    }
    throw new AttributeNotFoundException("Attribute " + attribute + " not found");
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 34 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project spf4j by zolyfarkas.

the class ExportedValuesMBean method setAttribute.

/**
 * {@inheritDoc}
 */
@Override
public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException {
    String name = attribute.getName();
    ExportedValue<Object> result = (ExportedValue<Object>) exportedValues.get(name);
    if (result == null) {
        throw new AttributeNotFoundException(name);
    }
    try {
        result.set(attribute.getValue());
    } catch (InvalidObjectException | RuntimeException ex) {
        LOG.warn("Exception while setting attr {}", attribute, ex);
        throw new InvalidAttributeValueException("Invalid value " + attribute + " detail:\n" + Throwables.toString(ex));
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) InvalidObjectException(java.io.InvalidObjectException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 35 with InvalidAttributeValueException

use of javax.management.InvalidAttributeValueException in project openj9 by eclipse.

the class AttributeData method testSetAttribute.

@Test
public final void testSetAttribute() {
    Attribute attr = null;
    try {
        // The one writable attribute of ClassLoadingMXBean...
        Boolean before = (Boolean) mbs.getAttribute(objName, "Verbose");
        // Toggle the boolean state of "isVerbose"
        boolean newVal = !before;
        attr = new Attribute("Verbose", new Boolean(newVal));
        mbs.setAttribute(objName, attr);
        Boolean after = (Boolean) mbs.getAttribute(objName, "Verbose");
        assert (newVal == after);
    } catch (AttributeNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected AttributeNotFoundException " + e.getMessage());
    } catch (InvalidAttributeValueException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InvalidAttributeValueException " + e.getMessage());
    } catch (MBeanException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected MBeanException " + e.getCause().getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException " + e.getCause().getMessage());
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    }
    // Let's try and set some non-writable attributes.
    attr = new Attribute("LoadedClassCount", new Integer(25));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("TotalLoadedClassCount", new Long(3300));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    attr = new Attribute("UnloadedClassCount", new Long(38));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e1) {
        AssertJUnit.assertTrue(e1 instanceof javax.management.AttributeNotFoundException);
        logger.debug("Exception occurred, as expected: " + e1.getMessage());
    }
    // Try and set the Verbose attribute with an incorrect type.
    attr = new Attribute("Verbose", new Long(42));
    try {
        mbs.setAttribute(objName, attr);
        Assert.fail("Unreacheable code: should have thrown an exception.");
    } catch (InstanceNotFoundException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
    } catch (ReflectionException e) {
        // An unlikely exception - if this occurs, we can't proceed with the test.
        Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
    } catch (Exception e2) {
        AssertJUnit.assertTrue(e2 instanceof javax.management.InvalidAttributeValueException);
        logger.debug("Exception occurred, as expected: " + e2.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Test(org.testng.annotations.Test)

Aggregations

InvalidAttributeValueException (javax.management.InvalidAttributeValueException)39 AttributeNotFoundException (javax.management.AttributeNotFoundException)26 ReflectionException (javax.management.ReflectionException)24 MBeanException (javax.management.MBeanException)23 Attribute (javax.management.Attribute)19 InstanceNotFoundException (javax.management.InstanceNotFoundException)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 RuntimeOperationsException (javax.management.RuntimeOperationsException)8 AttributeList (javax.management.AttributeList)6 IntrospectionException (javax.management.IntrospectionException)6 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)6 Test (org.testng.annotations.Test)6 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 Method (java.lang.reflect.Method)5 URI (java.net.URI)5 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 RuntimeErrorException (javax.management.RuntimeErrorException)5 Consumes (javax.ws.rs.Consumes)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5