Once again, I've failed at the exact same place ...
I tried to access a JMX bean programatically ... Everything went well (I'm using this wonderful spring infra for accessing my bean).
BUT ... when you try to access a bean that is not well exposed, according to standard, this won't work:
If you expose an
operation (and not as
attribute) that looks like
public String getServiceStatus()
since it starts by the prefix
get , it doesn't receive argument and it returns a value (not a void).
The standard requires that such method should be at least defined as attribute in the JMX server. If it is not, the javax.management.
MBeanServerInvocationHandler won't be able to access the operation.
You can see that in the
invoke() method of this
MBeanServerInvocationHandler()
if (methodName.startsWith("get")
&& methodName.length() > 3
&& nargs == 0
&& !returnType.equals(Void.TYPE)) {
return connection.getAttribute(objectName,
methodName.substring(3));
}
So the way I've found for overcoming this obstacle was ... to call another bean :(
Here's an
example of Spring usage for accessing JMX bean (it's not mine but it's similar):
<bean id="clientConnector"
class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl" value="service:jmx:rmi://remotehost:9875"/>
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName" value="bean:name=testBean"/>
<property name="proxyInterface" value="org.springframework.jmx.IJmxTestBean"/>
<property name="server" ref="clientConnector"/>
</bean>