I am trying to change the value of the proxyName in Catalina/Connector/8009/* connector. The problem is that I have the following exception when trying to find the MBean name.
Exception in thread "main" java.lang.ClassCastException: Cannot cast java.lang.String to javax.management.QueryExp
at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361)
at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356)
at jdk.nashorn.internal.scripts.Script$jmx_test_jjs.:program(jmx-test.jjs:32)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
at jdk.nashorn.tools.Shell.apply(Shell.java:394)
at jdk.nashorn.tools.Shell.runScripts(Shell.java:323)
at jdk.nashorn.tools.Shell.run(Shell.java:169)
at jdk.nashorn.tools.Shell.main(Shell.java:133)
at jdk.nashorn.tools.Shell.main(Shell.java:112)
The script is:
#! /usr/java/jdk1.8.0_25/bin/jjs
var host="jmxremotehost"
var port=7091
var serviceURL = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"
var url = new javax.management.remote.JMXServiceURL(serviceURL);
var stringArrayType = Java.type("java.lang.String[]")
var credentials = new stringArrayType(2)
credentials[0]="jmxuser"
credentials[1]="jmxpassword"
var HashMapType = Java.type("java.util.HashMap")
var environment = new HashMapType()
environment.put("jmx.remote.credentials",credentials)
var connector = javax.management.remote.JMXConnectorFactory.connect(url,environment)
var mbeanServerConnection=connector.getMBeanServerConnection()
var ObjectNameType = Java.type("javax.management.ObjectName")
objectName = new ObjectNameType('Catalina:type=Connector,port=8009,*')
print(mbeanServerConnection.queryNames(objectName, "proxyName"), null)
The problem is that I do not know how to send the Java null
or anything else valid for the 2nd parameter in queryNames() method of MBeanServerConnection interface.
See: http://docs.oracle.com/javase/7/docs/api/javax/management/MBeanServerConnection.html#queryMBeans%28javax.management.ObjectName,%20javax.management.QueryExp%29
Just using null works for me:
I trimmed down the script a bit, and used the platform MBeanServer to save some time:
The output was:
Slightly newer Java version, but I don't think that's at issue.
Update
Tried a remote connection to an HBase server and ran a pattern search for a more similar test:
Output was: