Today I had the same issue what Oz0234 described above (using TomEE 1.7.0 on Windows) but I did not understand for a while why the ProxyBean solution does not work at all with any Catalina objects.
It works with the MBeanServerConnection.getAttribute(objectName, attribute) method but it does not work using the proxy bean methods. I have checked and tested many.
Finally I have found why this happens. The answer is that the attribute names in Catalina domain start with lower case letter while the attribute names in other domains (java.lang, java.nio, openejb, ...) start with upper case letter as described here: http://docs.oracle.com/javase/7/docs/api/javax/management/JMX.html
I have extracted the most relevant part:
MyMXBean proxy = JMX.newMXBeanProxy(mbs, name, MyMXBean.class);
Suppose, for example, MyMXBean looks like this:
public interface MyMXBean {
public String getSimpleAttribute();
public void setSimpleAttribute(String value);
public MemoryUsage getMappedAttribute();
public void setMappedAttribute(MemoryUsage memoryUsage);
public MemoryUsage someOperation(String param1, MemoryUsage param2);
}
Then proxy.getSimpleAttribute() will result in a call to
mbs.getAttribute(name, "SimpleAttribute").
You can see the above example that the attribute's name starts with upper case letter "S"impleAttribute as the proxy bean getter name getSimpleAttribute. Unfortunately this is exactly the opposite what the bean's getter/setter naming convention describes.
Also I have checked other Tomcat Domain Objects' (Catalina,Users) attributes available on the JMX connection and I have compared some other attributes as well. If an attribute name starts with upper case letter, the bean proxy works. If it starts with lower case letter, only the getAttribute method works, like this:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
try(JMXConnector jmxc = JMXConnectorFactory.connect(url)) {
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("Catalina:type=Manager,context=/,host=localhost");
Object value = mbsc.getAttribute(mbeanName, "activeSessions");
}
So you need to pay attention which method you choose.