我試圖更改Catalina/Connector/8009/*連接器中的proxyName的值。問題是,在嘗試查找MBean名稱時出現以下異常。使用Nashorn查找JMX MBeans javascript jjs
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)
的腳本是:
#! /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)
的問題是,我不知道如何發送了Java null
或其他任何有效的queryNames(第二個參數的MBeanServerConnection接口)方法。 見:http://docs.oracle.com/javase/7/docs/api/javax/management/MBeanServerConnection.html#queryMBeans%28javax.management.ObjectName,%20javax.management.QueryExp%29
那' 「的proxyName」'是不是好的....複製/粘貼編碼....謝謝你,尼古拉斯 –
第二個',null'是不需要的。 –
你如何轉換爲JavaScript數組的結果?我正在使用'mbeanServerConnection.queryNames(objectName,null).toArray()[0]'來收集第一個元素。但它看起來不夠優雅。 –