# command line JMX applet to start/stop recording via ModuleLiveStreamRecord

**URL:** <https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [November 1, 2010, 4:20pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657 "2010-11-01T16:20:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/system/32/447_2.png) [@system](https://community.wowza.com/u/system)\
**Post date:** [November 1, 2010, 4:20pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/1 "2010-11-01T16:20:38Z")

</div>

I want to use a command line JMX client to start/stop recording of a stream. I have successfully installed the module ModuleLiveStreamRecord. I can use a JMX GUI client to start and stop recording the stream. However, I am confused as to how I specify the correct parameters on the command line. I modified the code from here [https://www.wowza.com/docs/how-to-set-up-a-command-line-interface-to-wowza-api-to-start-stop-vhost-using-jmx](https://www.wowza.com/docs/how-to-set-up-a-command-line-interface-to-wowza-api-to-start-stop-vhost-using-jmx) to add this capability.

I am using this command line:

./run.sh -jmx service:jmx:rmi://h264web.com:8084/jndi/rmi://h264web.com:8085/jmxrmi -user \*\*\*\*\*\* -pass \*\*\*\*\*\*\* startRecording _defaultVHost_:rtplive/_definst_ rtplive 1.stream /root/foobar.mp4

I get this error when I do this:

“ERROR: doInvoke: javax.management.MBeanException: Cannot find operation recordStream”

Any ideas?

New code (added to code from here [https://www.wowza.com/docs/how-to-set-up-a-command-line-interface-to-wowza-api-to-start-stop-vhost-using-jmx](https://www.wowza.com/docs/how-to-set-up-a-command-line-interface-to-wowza-api-to-start-stop-vhost-using-jmx), and I’m omitting things like where I defined CMD\_STARTRECORDING)

```auto
			else 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] );
				AppConextName context = new AppConextName(args[argOffset+1], true);
				String connectsName = MBEANNAME+":vHosts=VHosts,vHostName="+context.vhostName+",applications=Applications,applicationName="+context.appName+",applicationInstances=ApplicationInstances,applicationInstanceName="+context.appInstName+",name=ApplicationInstance";
				ObjectName connectsObjName = new ObjectName(connectsName);
				// pass 0 and true as second and third arguments
				Object[] arguments = {args[argOffset+2], "0", "true", args[argOffset+3]};
				String[] signature = {"java.lang.String", "int", "boolean", "java.lang.String"};
				[B]doInvoke(connection, connectsObjName, "recordStream", arguments, signature);[/B]
			}

```

Here is a screenshot of the GUI JMX client which shows the operations available and clearly one of them is marked as “recordStream”.

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [November 2, 2010, 7:51pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/2 "2010-11-02T19:51:01Z")

</div>

I’m really not sure, but I noticed your command line says “startRecording” but the screen shot shows an operation “recordStream”

Richard

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [November 4, 2010, 10:26pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/3 "2010-11-04T22:26:09Z")

</div>

The problem is that you are not going deep enough into the tree. you are stopping at appInstance instead of going to module/instance.

> WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=live,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance
> 
> connectsName in your code should resolve to the same as the MBeanInfo / ObjectName value, in jconsole, for the MBean you are trying to work with.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [November 5, 2010, 12:57am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/4 "2010-11-05T00:57:05Z")

</div>

The error is different. You are looking in the right place now but the method is wrong.

It looks like you are only passing 4 args to the recordStream method. If you haven’t modified ModuleLiveStreamRecord from the LiveStreamRecord package then it is expecting 7 args.

> public void recordStream(String streamName, int format, boolean append, String outputPath, boolean versionFile, boolean startOnKeyFrame, boolean recordData)
> 
> The error is telling you that it cannot find a method with the signiture
> 
> > public void recordStream(String, int, boolean, String)

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [November 5, 2010, 1:55am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/5 "2010-11-05T01:55:14Z")

</div>

> 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”};
> 
> arg 1 should be an int and arg 2 should be a boolean. You have them as Strings.

---

<div class="post-metadata">

**Author:** ![Roger\_Littin](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Roger\_Littin](https://community.wowza.com/u/Roger_Littin)\
**Post date:** [December 8, 2010, 7:55pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/6 "2010-12-08T19:55:18Z")

</div>

> Latest version of the app:
> 
> ```auto
> 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());
> }
> }
> }
> 
> ```

With the following change

```auto
	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
		[b]final Object[] arguments = {args[argOffset+2], 0, true, args[argOffset+3], true, true, true };[/b]
		final String[] signature = {"java.lang.String", "int", "boolean", "java.lang.String", "boolean", "boolean", "boolean"};
		doInvoke(connection, connectsObjName, "recordStream", arguments, signature);
	}

```

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [September 28, 2011, 3:38pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/7 "2011-09-28T15:38:25Z")

</div>

Before doing this you have to publish a live stream or start a MediaCaster stream in StreamManager. Then the stream, the application and tat application instance ( _definst_ ) will exist.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [October 14, 2013, 8:06pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/8 "2013-10-14T20:06:17Z")

</div>

The problem is that command by itself does not start the application instance. Run this command first:

```auto
java -cp . JMXCommandLine startAppInstance "live/_definst_"

```

That will start _defaultVHost_ and the application/appInsance

Richard

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 3, 2010, 8:32am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/9 "2010-11-03T08:32:00Z")

</div>

Richard,

Yes, I named the switch for the command line that, but I do send the correct thing (“recordStream”), AFAICT, to the jmx server.

I think what I would like confirmation on more than anything is whether this is correct in my switches:

_defaultVHost:rtplive/definst_

_In this code:_

 

_```auto_

_AppConextName context = new AppConextName(args[argOffset+1], true);
String connectsName = MBEANNAME+":vHosts=VHosts,vHostName="+context.vhostName+",applications=Applications,applicationName="+context.appName+",applicationInstances=ApplicationInstances,applicationInstanceName="+context.appInstName+",name=ApplicationInstance";
ObjectName connectsObjName = new ObjectName(connectsName);_

_```_

 

_I believe this is the correct way to address the module installed in the conf/rtplive/Application.xml file._

_xrd@xrd:~$ grep -i record /usr/local/WowzaMediaServer/conf/rtplive/Application.xml_

_ModuleLiveStreamRecord_

_Can anyone confirm this?_

_I’m going to remove all the other functionality of this java program and then post the complete file to see if that provides more context for the problem._

_Thanks,_

_Chris_

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 3, 2010, 8:45am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/10 "2010-11-03T08:45:18Z")

</div>

I stripped the file down to what is below. If I run with this command line I get this:

```auto
./run.sh -jmx service:jmx:rmi://h264web.com:8084/jndi/rmi://h264web.com:8085/jmxrmi -user *****-pass***** recordStream _defaultVHost_:rtplive/_definst_ rtplive 1.stream /root/foobar.mp4
Record: #1) recordStream #2) _defaultVHost_:rtplive/_definst_ #3) rtplive #4) 1.stream
ERROR: doInvoke: javax.management.MBeanException: Cannot find operation recordStream

```

Here is the full program I am using:

```auto
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, boolean startWithDefaults)
		{
			if (startWithDefaults)
			{
				vhostName = DEFAULT_VHOST;
				appName = DEFAULT_APPLICATION;
				appInstName = DEFAULT_APPINSTANCE;
			}
			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;
				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(Object valueObj)
	{
		long ret = 0;
		if (valueObj != null)
		{
			try
			{
				ret = Long.parseLong(valueObj.toString());
			}
			catch(Exception e)
			{
			}
		}
		return ret;
	}
	public static Object doInvoke(MBeanServerConnection connection, ObjectName connectsObjName, String cmdStr, Object[] arguments, String[] signature)
	{
		Object returnObj = null;
		try
		{
			returnObj = connection.invoke(connectsObjName, cmdStr, arguments, signature);
		}
		catch(Exception e)
		{
			System.out.println("ERROR: doInvoke: "+e.toString());
		}
		return returnObj;
	}
	public static Object doGetAttribute(MBeanServerConnection connection, ObjectName connectsObjName, String attributeName)
	{
		Object returnObj = null;
		try
		{
			returnObj = connection.getAttribute(connectsObjName, attributeName);
		}
		catch(Exception e)
		{
		}
		return returnObj;
	}
	public static void main(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
			JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
			// create a environment hash with username and password
			Map<String, Object> env = new HashMap<String, Object>();
			if (username != null && password != null)
			{
				String[] creds = {username, password};
				env.put(JMXConnector.CREDENTIALS, creds);
			}
			JMXConnector connector = JMXConnectorFactory.connect(serviceURL, env);
			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] );
				AppConextName context = new AppConextName(args[argOffset+1], true);
				String connectsName = MBEANNAME+":vHosts=VHosts,vHostName="+context.vhostName+",applications=Applications,applicationName="+context.appName+",applicationInstances=ApplicationInstances,applicationInstanceName="+context.appInstName+",name=ApplicationInstance";
				ObjectName connectsObjName = new ObjectName(connectsName);
				// pass 0 and true as second and third arguments
				Object[] arguments = {args[argOffset+2], "0", "true", args[argOffset+3]};
				String[] signature = {"java.lang.String", "int", "boolean", "java.lang.String"};
				doInvoke(connection, connectsObjName, "recordStream", arguments, signature);
			}
			else if (args[argOffset].equalsIgnoreCase(CMD_STOPRECORDING))
			{
				System.out.println(args[argOffset]+" "+args[argOffset+1]);
				AppConextName context = new AppConextName(args[argOffset+1], true);
				String connectsName = MBEANNAME+":vHosts=VHosts,vHostName="+context.vhostName+",applications=Applications,applicationName="+context.appName+",applicationInstances=ApplicationInstances,applicationInstanceName="+context.appInstName+",name=ApplicationInstance";
				ObjectName connectsObjName = new ObjectName(connectsName);
				Object[] arguments = {args[argOffset+2]};
				String[] signature = {"java.lang.String"};
				doInvoke(connection, connectsObjName, "stopMediaCasterStream", arguments, signature);
			}
			else
				System.out.println("ERROR: Command not recognized: "+args[argOffset]);
			}
		catch (Exception e)
		{
			System.out.println("ERROR: "+e.toString());
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 4, 2010, 1:21pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/11 "2010-11-04T13:21:35Z")

</div>

Anyone interested in installing this module and seeing if it works for them using the parameters I specified? I am thinking there is something related to the parameter:

“_defaultVHost_:rtplive/_definst_”

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 4, 2010, 4:05pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/12 "2010-11-04T16:05:16Z")

</div>

Roger,

Thanks for your help.

I think I am closer. I put a line to print out the “Object Name” inside my code (on line 233). When I run it, I get this now:

```auto
Using: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=rtplive,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance
ERROR: doInvoke: javax.management.ReflectionException: Cannot find method recordStream with this signature

```

So, still have an issue. But, if I look at the JMX console and view the string inside Object Name, I see this:

_WowzaMediaServerPro:vHosts=VHosts,vHostName=defaultVHost,applications=Applications,applicationName=rtplive,applicationInstances=ApplicationInstances,applicationInstanceName=definst,modules=Modules,module=ModuleLiveStreamRecord,name=Instance_

_Which is exactly the same as what I get when I print it out inside my java app._

_WowzaMediaServerPro:vHosts=VHosts,vHostName=defaultVHost,applications=Applications,applicationName=rtplive,applicationInstances=ApplicationInstances,applicationInstanceName=definst,modules=Modules,module=ModuleLiveStreamRecord,name=Instance_

_Enclosed is the screenshot of where I am looking inside the JMX console. And, I can see that there is an operation “recordStream” exposed there, but the app says “Can’t find method…”_

_Chris_

_![](http://vivoh.com/jmx2.png)_

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 4, 2010, 5:11pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/13 "2010-11-04T17:11:26Z")

</div>

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:

```auto
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());
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Chris\_Dawson](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Chris\_Dawson](https://community.wowza.com/u/Chris_Dawson)\
**Post date:** [November 5, 2010, 2:15pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/14 "2010-11-05T14:15:01Z")

</div>

Roger,

Does it show that I have a background in Perl and Ruby, languages which do that for me? 🙂

Thanks so much for your help. All is well now!

Chris

---

<div class="post-metadata">

**Author:** ![Sean\_conry](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sean\_conry](https://community.wowza.com/u/Sean_conry)\
**Post date:** [October 5, 2011, 5:37pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/15 "2011-10-05T17:37:45Z")

</div>

Nice write up,

however i get the error

Error: Could not find or load main class JMXCommandLine

when i schedule a cron job, but if i run the command at shell all it ok

and yes i have compile the files i get two files JMXCommandLine.class & JMXCommandLine$AppConextName.class that are placed in the /usr/ directory

command used

/usr/./jmxcl.sh -jmx service:jmx:rmi://localhost:8084/jndi/rmi://localhost:8085/jmxrmi -user admin -pass admin recordStream _defaultVHost_:test/_definst_ test /usr/local/WowzaMediaServer/content/test.flv true true true

where am i going wrong?

---

<div class="post-metadata">

**Author:** ![Sean\_conry](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sean\_conry](https://community.wowza.com/u/Sean_conry)\
**Post date:** [October 6, 2011, 8:34am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/16 "2011-10-06T08:34:59Z")

</div>

figured it out thanks guys

---

<div class="post-metadata">

**Author:** ![Tomas\_Alkyras](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@Tomas\_Alkyras](https://community.wowza.com/u/Tomas_Alkyras)\
**Post date:** [December 8, 2010, 10:59am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/17 "2010-12-08T10:59:11Z")

</div>

Maybe you could be so gentle and share the final code of your application and command lines to control?

---

<div class="post-metadata">

**Author:** ![Tomas\_Alkyras](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@Tomas\_Alkyras](https://community.wowza.com/u/Tomas_Alkyras)\
**Post date:** [December 8, 2010, 3:35pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/18 "2010-12-08T15:35:34Z")

</div>

Now seems it’s working, but I guess this script is for Wowza 2.0. Can it work with Wowza 1.7 ?

I’m not able to configure the starting line.

LiveStreamRecord works

with

Server: rtmp://my-ip/test

Stream: udp://0.0.0.0:13707

I’m trying to start with:

jmxcl -jmx service:jmx:rmi://localhost:8084/jndi/

rmi://localhost:8085/jmxrmi -user admin -pass \*\*\*\* recordStream _defaultVHost_:

test/_definst_ test 1.stream foobar.mp4

And I’m getting error

```auto
c:\Program Files\Java\jre6\bin>jmxcl -jmx service:jmx:rmi://localhost:8084/jndi/
rmi://localhost:8085/jmxrmi -user admin -pass admin recordStream _defaultVHost_:
test/_definst_ test 1.stream foobar.mp4
c:\Program Files\Java\jre6\bin>java -cp . JMXCommandLine -jmx service:jmx:rmi://
localhost:8084/jndi/rmi://localhost:8085/jmxrmi -user admin -pass **** recordSt
ream _defaultVHost_:test/_definst_ test 1.stream foobar.mp4
Using: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=A
pplications,applicationName=test,applicationInstances=ApplicationInstances,appli
cationInstanceName=_definst_,modules=Modules,module=ModuleLiveStreamRecord,name=
Instance
Record: #1) recordStream #2) _defaultVHost_:test/_definst_ #3) test #4) 1.stream
ERROR: doInvoke: javax.management.InstanceNotFoundException: WowzaMediaServerPro
:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationNam
e=test,applicationInstances=ApplicationInstances,applicationInstanceName=_defins
t_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance

```

---

<div class="post-metadata">

**Author:** ![Serg\_Lekseyev](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Serg\_Lekseyev](https://community.wowza.com/u/Serg_Lekseyev)\
**Post date:** [September 28, 2011, 9:22am UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/19 "2011-09-28T09:22:19Z")

</div>

Hi everyone, I’ve tried this java class to record video-stream from my WowzaMediaServer

and I got the same error

Tried on Widows,Ubuntu ; used Wowsa 2.2.4 and 2.2.0 =\> problem is still not solved

> ERROR: doInvoke: javax.management.InstanceNotFoundException: WowzaMediaServerPro
> 
> :vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationNam
> 
> e=test,applicationInstances=ApplicationInstances,applicationInstanceName=\_defins
> 
> t\_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance
> 
> any ideas?

---

<div class="post-metadata">

**Author:** ![Daljit\_Singh](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@Daljit\_Singh](https://community.wowza.com/u/Daljit_Singh)\
**Post date:** [October 14, 2013, 4:08pm UTC](https://community.wowza.com/t/command-line-jmx-applet-to-start-stop-recording-via-modulelivestreamrecord/657/20 "2013-10-14T16:08:17Z")

</div>

HI, I am trying it , bur getting below error:–

Using: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=nexgorigin,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance

Record: #1) recordStream #2) _defaultVHost_:test/_definst_ #3) test.sdp #4) abc.mp4

ERROR: doInvoke: javax.management.InstanceNotFoundException: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=nexgorigin,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,modules=Modules,module=ModuleLiveStreamRecord,name=Instance

Please note:-Stream already published from the streammanager.

Can some one please help in this regard.

Dsingh
