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); }
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, IOException { if (logger.debugOn()) logger.debug("setAttribute", "name=" + name + ", attribute=" + attribute); 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); } }
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); } }
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); }
@Override public synchronized void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Attribute newAttribute = attribute; if (configBeanModificationDisabled.get()) { throw new IllegalStateException("Operation is not allowed now"); } if ("Attribute".equals(newAttribute.getName())) { setAttribute((Attribute) newAttribute.getValue()); return; } try { if (newAttribute.getValue() instanceof ObjectName) { newAttribute = fixDependencyAttribute(newAttribute); } else if (newAttribute.getValue() instanceof ObjectName[]) { newAttribute = fixDependencyListAttribute(newAttribute); } internalServer.setAttribute(objectNameInternal, newAttribute); } catch (final InstanceNotFoundException e) { throw new MBeanException(e); } }
@Override public AttributeList setAttributes(final AttributeList attributes) { AttributeList result = new AttributeList(); for (Object attributeObject : attributes) { Attribute attribute = (Attribute) attributeObject; try { setAttribute(attribute); result.add(attribute); } catch (final InvalidAttributeValueException | AttributeNotFoundException | MBeanException | ReflectionException e) { LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e); throw new IllegalArgumentException( "Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e); } } return result; }
@Override public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { ConfigDescriptor desc = descLookupByAttributeName.get(attribute.getName()); if (desc == null) { log.warn("Attribute Set name={} value={} requested on MXBean {}, but no matching configDescriptor found.", attribute.getName(), attribute.getValue(), mbeanName); throw new AttributeNotFoundException(); } // get appropriate config value converter and test the conversion for immediate error feedback ConfigValueConverter<?> converter = (ConfigValueConverter<?>) this.injectorRef.get().getInstance(Key.get(Types.newParameterizedType(ConfigValueConverter.class, desc.getConfigType()))); String strValue = attribute.getValue() == null ? null : attribute.getValue().toString(); try { converter.apply(strValue); } catch (Exception ex) { log.warn("Attribute Set name={} value={} requested on MXBean {}, but value failed to convert to type {}", attribute.getName(), attribute.getValue(), mbeanName, desc.getConfigType().getTypeName()); throw new InvalidAttributeValueException("Failed to parse value: " + ex.getMessage()); } // emit event this.eventSink.fireEvent(desc.getConfigName(), Optional.ofNullable(strValue)); }
@Override public AttributeList setAttributes(AttributeList attributes) { List<String> toGet = new ArrayList<>(); for (Attribute attrib : attributes.asList()) { try { setAttribute(attrib); toGet.add(attrib.getName()); } catch (AttributeNotFoundException | InvalidAttributeValueException | MBeanException | ReflectionException ex) { // warn is logged by individual setAttribute calls log.debug("Could not set attribute {} on MXBean {}", attrib.getName(), mbeanName, ex); } } return getAttributes(toGet.stream().toArray(String[]::new)); }
@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; }
@Override public void setAttribute( Attribute attribute ) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { UnitOfWork uow = uowf.newUnitOfWork(); try { EntityComposite configuration = uow.get( EntityComposite.class, identity ); AssociationStateHolder state = spi.stateOf( configuration ); AccessibleObject accessor = propertyNames.get( attribute.getName() ); Property<Object> property = state.propertyFor( accessor ); property.set( attribute.getValue() ); try { uow.complete(); } catch ( UnitOfWorkCompletionException e ) { throw new ReflectionException( e ); } } finally { uow.discard(); } }
@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; }
@Override public void setAttribute(final Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { try { String name = attribute.getName(); Object value = attribute.getValue(); attribute(name).setValue(value); } catch (Exception e) { log.warn("Failed to set attribute: {}", attribute, e); // TODO: Sort out the proper exception handling/wrapping Throwables.propagateIfPossible(e, AttributeNotFoundException.class); Throwables.propagateIfPossible(e, InvalidAttributeValueException.class); Throwables.propagateIfPossible(e, MBeanException.class); Throwables.propagateIfPossible(e, ReflectionException.class); throw new MBeanException(e); } }
/** * @return */ private XMLSettingsHandler getSettingsHandler() { XMLSettingsHandler settings = job.getSettingsHandler(); if (settings == null || settings.getOrder() == null) { File profile = new File(job.getDirectory() + File.separator + PROFILE_NAME); try { settings = new XMLSettingsHandler(profile); settings.initialize(); } catch (InvalidAttributeValueException e) { if (log.isErrorEnabled()) { log.error("Failed to get settings for job " + name + ": " + e.getMessage(), e); } throw new HarvesterException("Failed to get settings for job " + name + ": " + e.getMessage(), e); } } return settings; }
private void applyPartialUpdate(String attribute, String subAttribute, List<Map<String, Object>> list, int index, Object value, Class <? extends BaseScimResource> cls) throws InvalidAttributeValueException { if (subAttribute.length()==0) { //Updates the whole item in the list after passing mutability check, see section 3.5.2 RFC 7644: //"Each operation against an attribute MUST be compatible with the attribute's mutability and schema ... " Map<String, Object> map=IntrospectUtil.strObjMap(value); for (String subAttr : map.keySet()) assertMutability(attribute, list.get(index).get(subAttr), map.get(subAttr), cls); list.set(index, map); } else{ //Updates a subattribute only assertMutability(attribute + "." + subAttribute, list.get(index).get(subAttribute), value, cls); list.get(index).put(subAttribute, value); } }
private static BaseScimResource transferToResource(BaseScimResource origin, final BaseScimResource destination, List<Extension> extensions, boolean replacing) throws InvalidAttributeValueException{ log.debug("transferToResource. Processing {} operation", replacing ? "replace" : "add"); Map<String, Object> fromMap = mapper.convertValue(origin, new TypeReference<Map<String,Object>>(){}); Map<String, Object> toMap = mapper.convertValue(destination, new TypeReference<Map<String,Object>>(){}); log.debug("transferToResource. Recursive traversal of resource is taking place"); traversalClass tclass=new traversalClass(origin.getClass()); tclass.traverse("", fromMap, toMap, replacing); attachExtensionInfo(fromMap, toMap, extensions, replacing); if (tclass.error==null) return mapper.convertValue(toMap, origin.getClass()); else throw new InvalidAttributeValueException(tclass.error); }
/** * Returns a SCIM resource with the same data found in <code>origin</code> object, except for the attribute referenced * by <code>path</code> being removed from the output. In other words, this method nullifies an attribute. * @param origin The resource having the the original data * @param path An attribute path (in dot notation). Examples could be: <code>displayName, emails.type, addresses, * meta.lastModified</code>. * @param extensions A list of <code>Extension</code>s associated to <code>origin</code> Object * @return The resulting object: data in origin without the attribute referenced by <code>path</code> * @throws InvalidAttributeValueException If there is an attempt to remove an attribute annotated as {@link Attribute#isRequired() * required} or {@link org.gluu.oxtrust.model.scim2.AttributeDefinition.Mutability#READ_ONLY read-only} */ public static BaseScimResource deleteFromResource(BaseScimResource origin, String path, List<Extension> extensions) throws InvalidAttributeValueException { Field f=IntrospectUtil.findFieldFromPath(origin.getClass(), path); if (f!=null){ Attribute attrAnnot = f.getAnnotation(Attribute.class); if (attrAnnot != null && (attrAnnot.mutability().equals(READ_ONLY) || attrAnnot.isRequired())) throw new InvalidAttributeValueException("Cannot remove read-only or required attribute " + path); } Map<String, Object> map = mapper.convertValue(origin, new TypeReference<Map<String,Object>>(){}); traversalClass tclass=new traversalClass(origin.getClass()); if (f==null) //Extensions stuff deleteCustomAttribute(map, path, extensions); else tclass.traverseDelete(map, path); return mapper.convertValue(map, origin.getClass()); }
@Override public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, SET_ATTRIBUTE, attribute.getName(), JmxAction.Impact.WRITE); delegate.setAttribute(name, attribute); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof AttributeNotFoundException) throw (AttributeNotFoundException)e; if (e instanceof InvalidAttributeValueException) throw (InvalidAttributeValueException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).setAttribute(name, attribute); } } }