WriteHandler extends JsonRequestHandler<JmxWriteRequest> { @Override public Object doHandleRequest(MBeanServerConnection server, JmxWriteRequest request) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException { try { return setAttribute(request, server); } catch (IntrospectionException exp) { throw new IllegalArgumentException("Cannot get info for MBean " + request.getObjectName() + ": " +exp,exp); } catch (InvalidAttributeValueException e) { throw new IllegalArgumentException("Invalid value " + request.getValue() + " for attribute " + request.getAttributeName() + ", MBean " + request.getObjectNameAsString(),e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot set value " + request.getValue() + " for attribute " + request.getAttributeName() + ", MBean " + request.getObjectNameAsString(),e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("Cannot set value " + request.getValue() + " for attribute " + request.getAttributeName() + ", MBean " + request.getObjectNameAsString(),e); } } WriteHandler(Restrictor pRestrictor, Converters pConverters); @Override RequestType getType(); @Override Object doHandleRequest(MBeanServerConnection server, JmxWriteRequest request); @Override boolean useReturnValueWithPath();  }
@Test public void map() throws Exception { Map map = new HashMap<String,Integer>(); map.put("answer",42); JmxWriteRequest req = new JmxRequestBuilder(WRITE,oName).attribute("Map").value(map).build(); handler.doHandleRequest(getMBeanServer(),req); req = new JmxRequestBuilder(WRITE,oName).attribute("Map").value(null).build(); Map ret = (Map) handler.doHandleRequest(getMBeanServer(),req); assertTrue(ret instanceof Map); assertEquals(((Map) ret).get("answer"),42); }
@Test(expectedExceptions = {AttributeNotFoundException.class}) public void invalidAttribute() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException { JmxWriteRequest req = new JmxRequestBuilder(WRITE,oName).attribute("ReadOnly").value("Sommer").build(); handler.doHandleRequest(getMBeanServer(),req); }
@Test public void invalidValue() throws Exception { JmxWriteRequest req = new JmxRequestBuilder(WRITE,oName).attribute("Boolean").value(10).build(); handler.doHandleRequest(getMBeanServer(),req); }