javax.management.InvalidAttributeValueException Java Examples

The following examples show how to use javax.management.InvalidAttributeValueException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RMIConnectorLogAttributesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
Example #2
Source File: JmxHelper.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private boolean shouldRetryOn(Exception e) {
    // Expect SecurityException, IOException, etc.
    // But can also see things like javax.naming.ServiceUnavailableException with WSO2 app-servers.
    // So let's not try to second guess strange behaviours that future entities will exhibit.
    //
    // However, if it was our request that was invalid then not worth retrying.
    
    if (e instanceof AttributeNotFoundException) return false;
    if (e instanceof InstanceAlreadyExistsException) return false;
    if (e instanceof InstanceNotFoundException) return false;
    if (e instanceof InvalidAttributeValueException) return false;
    if (e instanceof ListenerNotFoundException) return false;
    if (e instanceof MalformedObjectNameException) return false;
    if (e instanceof NotCompliantMBeanException) return false;
    if (e instanceof InterruptedException) return false;
    if (e instanceof RuntimeInterruptedException) return false;

    return true;
}
 
Example #3
Source File: DynamicMBeanWrapper.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void setAttribute(final Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
    MBeanException, ReflectionException {
    if (setters.containsKey(attribute.getName())) {
        final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classloader);
        try {
            setters.get(attribute.getName()).invoke(instance, attribute.getValue());
        } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
            logger.error("can't set " + attribute + " value", e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    } else {
        throw new AttributeNotFoundException();
    }
}
 
Example #4
Source File: DataSourceConfigurationManagerService.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public AttributeList setAttributes( AttributeList attributeList )
{
    AttributeList list = new AttributeList();
    for ( int i = 0; i < list.size(); i++ ) {
        Attribute attribute = ( Attribute ) list.get( i );

        try {
            setAttribute( attribute );
            list.add( attribute );
        } catch ( AttributeNotFoundException | InvalidAttributeValueException | ReflectionException | MBeanException e ) {
            e.printStackTrace();
        }
    }

    return list;
}
 
Example #5
Source File: RMIConnectorLogAttributesTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
Example #6
Source File: PerInterface.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
void setAttribute(Object resource, String attribute, Object value,
                  Object cookie)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {

    final M cm = setters.get(attribute);
    if (cm == null) {
        final String msg;
        if (getters.containsKey(attribute))
            msg = "Read-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    introspector.invokeSetter(attribute, cm, resource, value, cookie);
}
 
Example #7
Source File: PerInterface.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
void setAttribute(Object resource, String attribute, Object value,
                  Object cookie)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {

    final M cm = setters.get(attribute);
    if (cm == null) {
        final String msg;
        if (getters.containsKey(attribute))
            msg = "Read-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    introspector.invokeSetter(attribute, cm, resource, value, cookie);
}
 
Example #8
Source File: RMIConnector.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #9
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #10
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #11
Source File: MBeanIntrospector.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void maybeInvalidParameter(String name, M setter, Object arg,
        Object cookie)
        throws InvalidAttributeValueException {
    if (!validParameter(setter, arg, 0, cookie)) {
        final String msg =
                "Invalid value for attribute " + name + ": " + arg;
        throw new InvalidAttributeValueException(msg);
    }
}
 
Example #12
Source File: MBeanServerAccessController.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example #13
Source File: MBeanServerDelegateImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * This method always fail since all MBeanServerDelegateMBean attributes
 * are read-only.
 *
 * @param attribute The identification of the attribute to
 * be set and  the value it is to be set to.
 *
 * @exception AttributeNotFoundException
 */
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {

    // Now we will always fail:
    // Either because the attribute is null or because it is not
    // accessible (or does not exist).
    //
    final String attname = (attribute==null?null:attribute.getName());
    if (attname == null) {
        final RuntimeException r =
            new IllegalArgumentException("Attribute name cannot be null");
        throw new RuntimeOperationsException(r,
            "Exception occurred trying to invoke the setter on the MBean");
    }

    // This is a hack: we call getAttribute in order to generate an
    // AttributeNotFoundException if the attribute does not exist.
    //
    Object val = getAttribute(attname);

    // If we reach this point, we know that the requested attribute
    // exists. However, since all attributes are read-only, we throw
    // an AttributeNotFoundException.
    //
    throw new AttributeNotFoundException(attname + " not accessible");
}
 
Example #14
Source File: MBeanSupport.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void setAttribute(Attribute attribute)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {
    final String name = attribute.getName();
    final Object value = attribute.getValue();
    perInterface.setAttribute(resource, name, value, getCookie());
}
 
Example #15
Source File: MBeanIntrospector.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void maybeInvalidParameter(String name, M setter, Object arg,
        Object cookie)
        throws InvalidAttributeValueException {
    if (!validParameter(setter, arg, 0, cookie)) {
        final String msg =
                "Invalid value for attribute " + name + ": " + arg;
        throw new InvalidAttributeValueException(msg);
    }
}
 
Example #16
Source File: PluggableMBeanServerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException,
        InvalidAttributeValueException, MBeanException, ReflectionException {
    ClassLoader old = pushClassLoader(name);
    try {
        delegate.setAttribute(name, attribute);
    } finally {
        resetClassLoader(old);
    }
}
 
Example #17
Source File: MBeanIntrospector.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void maybeInvalidParameter(String name, M setter, Object arg,
        Object cookie)
        throws InvalidAttributeValueException {
    if (!validParameter(setter, arg, 0, cookie)) {
        final String msg =
                "Invalid value for attribute " + name + ": " + arg;
        throw new InvalidAttributeValueException(msg);
    }
}
 
Example #18
Source File: OldMBeanServerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {
    String name = attribute.getName();
    AttrMethods am = attrMap.get(name);
    if (am == null || am.setter == null)
        throw new AttributeNotFoundException(name);
    invokeMethod(am.setter, attribute.getValue());
}
 
Example #19
Source File: MBeanServerDelegateImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method always fail since all MBeanServerDelegateMBean attributes
 * are read-only.
 *
 * @param attribute The identification of the attribute to
 * be set and  the value it is to be set to.
 *
 * @exception AttributeNotFoundException
 */
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {

    // Now we will always fail:
    // Either because the attribute is null or because it is not
    // accessible (or does not exist).
    //
    final String attname = (attribute==null?null:attribute.getName());
    if (attname == null) {
        final RuntimeException r =
            new IllegalArgumentException("Attribute name cannot be null");
        throw new RuntimeOperationsException(r,
            "Exception occurred trying to invoke the setter on the MBean");
    }

    // This is a hack: we call getAttribute in order to generate an
    // AttributeNotFoundException if the attribute does not exist.
    //
    Object val = getAttribute(attname);

    // If we reach this point, we know that the requested attribute
    // exists. However, since all attributes are read-only, we throw
    // an AttributeNotFoundException.
    //
    throw new AttributeNotFoundException(attname + " not accessible");
}
 
Example #20
Source File: RMRest.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setMBeanInfo(String sessionId, ObjectName name, String type, String attr, String value)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException,
        NotConnectedException, MBeanException, AttributeNotFoundException, InvalidAttributeValueException,
        IllegalArgumentException {
    RMProxyUserInterface rm = checkAccess(sessionId);
    if ((type != null) && (attr != null) && (value != null)) {
        rm.setMBeanAttribute(name, type, attr, value);
    }
}
 
Example #21
Source File: MBeanServerDelegateImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method always fail since all MBeanServerDelegateMBean attributes
 * are read-only.
 *
 * @param attribute The identification of the attribute to
 * be set and  the value it is to be set to.
 *
 * @exception AttributeNotFoundException
 */
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {

    // Now we will always fail:
    // Either because the attribute is null or because it is not
    // accessible (or does not exist).
    //
    final String attname = (attribute==null?null:attribute.getName());
    if (attname == null) {
        final RuntimeException r =
            new IllegalArgumentException("Attribute name cannot be null");
        throw new RuntimeOperationsException(r,
            "Exception occurred trying to invoke the setter on the MBean");
    }

    // This is a hack: we call getAttribute in order to generate an
    // AttributeNotFoundException if the attribute does not exist.
    //
    Object val = getAttribute(attname);

    // If we reach this point, we know that the requested attribute
    // exists. However, since all attributes are read-only, we throw
    // an AttributeNotFoundException.
    //
    throw new AttributeNotFoundException(attname + " not accessible");
}
 
Example #22
Source File: MBeanServerAccessController.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example #23
Source File: OldMBeanServerTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {
    String name = attribute.getName();
    AttrMethods am = attrMap.get(name);
    if (am == null || am.setter == null)
        throw new AttributeNotFoundException(name);
    invokeMethod(am.setter, attribute.getValue());
}
 
Example #24
Source File: SnmpGenericObjectServer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the value of an SNMP variable.
 *
 * <p><b><i>
 * You should never need to use this method directly.
 * </i></b></p>
 *
 * @param meta  The impacted metadata object
 * @param name  The ObjectName of the impacted MBean
 * @param x     The new requested SnmpValue
 * @param id    The OID arc identifying the variable we're trying to set.
 * @param data  User contextual data allocated through the
 *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
 *
 * @return The new value of the variable after the operation.
 *
 * @exception SnmpStatusException whenever an SNMP exception must be
 *      raised. Raising an exception will abort the request. <br>
 *      Exceptions should never be raised directly, but only by means of
 * <code>
 * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
 * </code>
 **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name,
                     SnmpValue x, long id, Object data)
    throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue=
        meta.buildAttributeValue(id,x);
    final Attribute att = new Attribute(attname,attvalue);

    Object result = null;

    try {
        server.setAttribute(name,att);
        result = server.getAttribute(name,attname);
    } catch(InvalidAttributeValueException iv) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    }

    return meta.buildSnmpValue(id,result);
}
 
Example #25
Source File: MBeanIntrospector.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void maybeInvalidParameter(String name, M setter, Object arg,
        Object cookie)
        throws InvalidAttributeValueException {
    if (!validParameter(setter, arg, 0, cookie)) {
        final String msg =
                "Invalid value for attribute " + name + ": " + arg;
        throw new InvalidAttributeValueException(msg);
    }
}
 
Example #26
Source File: SnmpGenericObjectServer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Set the value of an SNMP variable.
 *
 * <p><b><i>
 * You should never need to use this method directly.
 * </i></b></p>
 *
 * @param meta  The impacted metadata object
 * @param name  The ObjectName of the impacted MBean
 * @param x     The new requested SnmpValue
 * @param id    The OID arc identifying the variable we're trying to set.
 * @param data  User contextual data allocated through the
 *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
 *
 * @return The new value of the variable after the operation.
 *
 * @exception SnmpStatusException whenever an SNMP exception must be
 *      raised. Raising an exception will abort the request. <br>
 *      Exceptions should never be raised directly, but only by means of
 * <code>
 * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
 * </code>
 **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name,
                     SnmpValue x, long id, Object data)
    throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue=
        meta.buildAttributeValue(id,x);
    final Attribute att = new Attribute(attname,attvalue);

    Object result = null;

    try {
        server.setAttribute(name,att);
        result = server.getAttribute(name,attname);
    } catch(InvalidAttributeValueException iv) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    }

    return meta.buildSnmpValue(id,result);
}
 
Example #27
Source File: PerfCounters.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setAttribute(Attribute attribute)
		throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
	if (attribute == null) {
		throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name cannot be null."),
				"Cannot invoke setAttribute on " + MBEAN_OBJECT_NAME + " with null as attribute name.");
	}
	Counter c = counterMap.get(attribute.getName());
	if (c == null) {
		throw new AttributeNotFoundException("Could not find the attribute " + attribute + ".");
	}
	throw new RuntimeOperationsException(new UnsupportedOperationException(),
			"All attributes on the PerfCounters MBean are read only.");
}
 
Example #28
Source File: ConfigurationMBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public AttributeList setAttributes(AttributeList attributes) {
    AttributeList successful = new AttributeList();
    for (Attribute attribute: attributes.asList()) {
        try {
            setAttribute(attribute);
            successful.add(attribute);
        } catch (AttributeNotFoundException | InvalidAttributeValueException | MBeanException | ReflectionException e) {
            // Ignore as we just won't return it in the result.
        }
    }
    return successful;
}
 
Example #29
Source File: ServerInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setAttribute(Attribute attribute) throws RemoteException, InstanceNotFoundException, AttributeNotFoundException,
InvalidAttributeValueException, MBeanException, ReflectionException, java.io.IOException {
    String attrName = attribute.getName();
    Set appList = new HashSet(Arrays.asList(JSR_SERVER_INFO));
    if(appList.contains(attrName)){
        this.conn.setAttribute(this.runtimeObjName, attribute);
    }
}
 
Example #30
Source File: MBeanServerAccessController.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}