if (sessionId == null) {
sessionId = this.sessionInfo.getSecuritySession().getSecretSessionId();
}
if (log.isLoggable(Level.FINER)) log.finer("get(" + oid + ")");
if (oid == null || oid.length() < 8) // "__cmd:" + 2 characters minimum
throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which is not null or too short");
String cmd = CommandWrapper.stripCommand(this.glob, oid);
if (cmd.startsWith(ContextNode.SCHEMA_JMX_DOMAIN)) { // JMX query starts with "org.xmlBlaster:"
// ObjectName = org.xmlBlaster:nodeClass=node,node="heron"
// org.xmlBlaster:nodeClass=node,node="heron"/action=getFreeMemStr
// org.xmlBlaster:nodeClass=node,node="heron"/action=usage?action=usage
// java -Djmx.invoke.getters=set ... org.xmlBlaster.Main
// org.xmlBlaster:nodeClass=node,node="heron"/action=getLastWarning?action=getLastWarning
// org.xmlBlaster:nodeClass=node,node="heron"/action=getLastWarning
// org.xmlBlaster:nodeClass=node,node="avalon_mycomp_com",clientClass=client,client="heron.mycomp.com",sessionClass=session,session="1"/action=getConnectionState
Object obj = JmxWrapper.getInstance(this.glob).invokeCommand(cmd);
StringBuffer ret = new StringBuffer(1024);
if (obj != null) {
if (obj instanceof MsgUnit) {
return new MsgUnit[] { (MsgUnit)obj };
}
else if (obj instanceof MsgUnit[]) {
return (MsgUnit[])obj;
}
else if (obj instanceof String[]) {
String[] str = (String[])obj;
for(int i=0; i<str.length; i++)
ret.append(str[i]).append("\n");
}
else {
ret.append(obj);
}
}
MsgUnit msgUnit = new MsgUnit("<key oid='__cmd:"+cmd+"'/>", ret.toString().getBytes(), "<qos/>");
return new MsgUnit[] { msgUnit };
}
try {
CommandWrapper w = new CommandWrapper(glob, oid);
if (args != null) w.setArgs(args);
String key = w.getThirdLevel();
if (w.getThirdLevel().startsWith("?")) {
key = "DEFAULT"; // One handler needs to register itself with "DEFAULT"
}
Object obj = this.handlerMap.get(key); // e.g. "topic" or "client" or "sysprop"
if (obj == null) {
throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Sorry can't process your command '" + oid + "', '" + w.getThirdLevel() + "' has no registered handler (key=" + key + ")");
}
I_CommandHandler handler = (I_CommandHandler)obj;
MsgUnit[] ret = handler.get(addressServer, sessionId, w);
if (ret == null) ret = new MsgUnit[0];
return ret;