More specifically it says “cannot find method with signature.”
I’m thinking I am getting closer. If I run the stopRecording command (after correcting a typo…), no complaints.
I changed the signature line in the code so the code has a signature like exposed in the JMX console.
But, now I get:
“ERROR: doInvoke: javax.management.MBeanException: Exception invoking method recordStream”
Latest version of the app:
import java.util.*;
import javax.management.*;
import javax.management.remote.*;
public class JMXCommandLine
{
public static final String MBEANNAME = "WowzaMediaServerPro";
public static final String CMD_STARTRECORDING = "recordStream";
public static final String CMD_STOPRECORDING = "stopRecording";
public static final String DEFAULT_VHOST = "_defaultVHost_";
public static final String DEFAULT_APPLICATION = "_defapp_";
public static final String DEFAULT_APPINSTANCE = "_definst_";
public static class AppConextName
{
String vhostName = null;
String appName = null;
String appInstName = null;
public AppConextName()
{
}
public AppConextName(String fullname, final boolean startWithDefaults)
{
if (startWithDefaults)
{
vhostName = DEFAULT_VHOST;
appName = DEFAULT_APPLICATION;
appInstName = DEFAULT_APPINSTANCE;
}
final int qloc = fullname.indexOf(":");
if (qloc >= 0)
{
vhostName = fullname.substring(0, qloc);
fullname = fullname.substring(qloc+1);
}
else
vhostName = DEFAULT_VHOST;
if (fullname.length() > 0)
{
appName = fullname;
final int sloc = fullname.indexOf("/");
if (sloc >= 0)
{
appName = fullname.substring(0, sloc);
appInstName = fullname.substring(sloc+1);
}
}
}
String getObjName()
{
String ret = "";
while(true)
{
if (vhostName == null)
break;
ret += "vHosts=VHosts,vHostName="+vhostName;
if (appName == null)
break;
ret += ",applications=Applications,applicationName="+appName;
if (appInstName == null)
break;
ret += ",applicationInstances=ApplicationInstances,applicationInstanceName="+appInstName;
break;
}
return ret;
}
}
public static void printUsage()
{
System.out.println("");
System.out.println("Usage:");
System.out.println("");
System.out.println("[command] -[switch [value]...] [command] [params...]");
System.out.println("");
System.out.println("Switches:");
System.out.println("");
System.out.println(" -jmx [jmx-url]");
System.out.println(" -user [jmx-username]");
System.out.println(" -pass [jmx-password]");
System.out.println("");
System.out.println("Commands:");
System.out.println("");
System.out.println(" " + CMD_STARTRECORDING + " [vhost:application/appInstance] [stream-name] path");
System.out.println(" " + CMD_STOPRECORDING + " [vhost:application/appInstance] [stream-name]");
System.out.println("");
}
public static long objToLong(final Object valueObj)
{
long ret = 0;
if (valueObj != null)
{
try
{
ret = Long.parseLong(valueObj.toString());
}
catch(final Exception e)
{
}
}
return ret;
}
public static Object doInvoke(final MBeanServerConnection connection, final ObjectName connectsObjName, final String cmdStr, final Object[] arguments, final String[] signature)
{
Object returnObj = null;
try
{
returnObj = connection.invoke(connectsObjName, cmdStr, arguments, signature);
}
catch(final Exception e)
{
System.out.println("ERROR: doInvoke: "+e.toString());
}
return returnObj;
}
public static Object doGetAttribute(final MBeanServerConnection connection, final ObjectName connectsObjName, final String attributeName)
{
Object returnObj = null;
try
{
returnObj = connection.getAttribute(connectsObjName, attributeName);
}
catch(final Exception e)
{
}
return returnObj;
}
public static void main(final String[] args)
{
try
{
for(int i=0;i<args.length;i++)
args[i] = args[i].trim();
String host = "localhost";
String username = null;
String password = null;
String jmxURL = "service:jmx:rmi://"+host+":8084/jndi/rmi://"+host+":8085/jmxrmi";
int argOffset = 0;
while(true)
{
if (argOffset >= args.length)
break;
if (!args[argOffset].startsWith("-"))
break;
if (args[argOffset].startsWith("-host"))
{
argOffset++;
host = args[argOffset];
jmxURL = "service:jmx:rmi://"+host+":8084/jndi/rmi://"+host+":8085/jmxrmi";
}
else if (args[argOffset].startsWith("-jmx"))
{
argOffset++;
jmxURL = args[argOffset];
}
else if (args[argOffset].startsWith("-user"))
{
argOffset++;
username = args[argOffset];
}
else if (args[argOffset].startsWith("-pass"))
{
argOffset++;
password = args[argOffset];
}
argOffset++;
}
if (argOffset >= args.length)
{
printUsage();
return;
}
// create a connection URL
final JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
final AppConextName context = new AppConextName(args[argOffset+1], true);
final String connectsName = MBEANNAME+":vHosts=VHosts,vHostName="+context.vhostName+",applications=Applications,applicationName="+context.appName+",applicationInstances=ApplicationInstances,applicationInstanceName="+context.appInstName+",modules=Modules,module=ModuleLiveStreamRecord,name=Instance";
System.out.println( "Using: " + connectsName );
final ObjectName connectsObjName = new ObjectName(connectsName);
// create a environment hash with username and password
final Map<String, Object> env = new HashMap<String, Object>();
if (username != null && password != null)
{
final String[] creds = {username, password};
env.put(JMXConnector.CREDENTIALS, creds);
}
final JMXConnector connector = JMXConnectorFactory.connect(serviceURL, env);
final MBeanServerConnection connection = connector.getMBeanServerConnection();
if (connection == null)
{
System.out.println("ERROR: Cannot connect to JMX interface: "+jmxURL);
return;
}
if (args[argOffset].equalsIgnoreCase(CMD_STARTRECORDING))
{
System.out.println("Record: #1) " + args[argOffset]+" #2) "+args[argOffset+1]+" #3) "+args[argOffset+2]+
" #4) "+args[argOffset+3] );
// pass 0 and true as second and third arguments
final Object[] arguments = {args[argOffset+2], "0", "true", args[argOffset+3], true, true, true };
final String[] signature = {"java.lang.String", "int", "boolean", "java.lang.String", "boolean", "boolean", "boolean"};
doInvoke(connection, connectsObjName, "recordStream", arguments, signature);
}
else if (args[argOffset].equalsIgnoreCase(CMD_STOPRECORDING))
{
System.out.println(args[argOffset]+" "+args[argOffset+1]);
final Object[] arguments = {args[argOffset+2]};
final String[] signature = {"java.lang.String"};
doInvoke(connection, connectsObjName, "stopRecording", arguments, signature);
}
else
System.out.println("ERROR: Command not recognized: "+args[argOffset]);
}
catch (final Exception e)
{
System.out.println("ERROR: "+e.toString());
}
}
}