Create an HTTP provider with the Wowza Streaming Engine Java API

HTTP providers send information to or obtain information from a Wowza Streaming Engine™ media server software instance and display that information on an HTTP web page. This article shows how to create and configure a basic custom HTTP provider using the Wowza Streaming Engine Java API.

Prerequisites


Install and configure the Wowza™ IDE for Eclipse. See Extend Wowza Streaming Engine using the Wowza IDE.

Create the provider


Each HTTP provider extends the HTTPProvider2Base as follows:

class MyHTTPProvider extends HTTPProvider2Base

This requires that you define the onHTTPRequest function (this is where you can handle each request made to the provider):

public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {}

Here's a simple provider that returns some XML with an output element that contains the string 'hello world':

class MyHTTPProvider extends HTTPProvider2Base {
	@Override
	public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {

		StringBuffer ret = new StringBuffer();
		ret.append("<?xml version="1.0"?>
<WowzaStreamingEngine>");
                ret.append("<output>Hello World!</output>");
                ret.append("</WowzaStreamingEngine>");
		try
		{
			resp.setHeader("Content-Type", "text/xml");

			OutputStream out = resp.getOutputStream();
			byte[] outBytes = ret.toString().getBytes();
			out.write(outBytes);
		}
		catch (Exception e)
		{
			WMSLoggerFactory.getLogger(HTTPServerVersion.class).error("HTTPProviderStreamReset.onHTTPRequest: "+e.toString());
			e.printStackTrace();
		}

	}
}

Configure the provider


Compile and run the HTTP provider, then put its .jar file in the [install-dir]/lib folder and add it to the VHost.xml file with the other admin host port 8086 providers as follows:

<HTTPProvider>
	<BaseClass>com.wowza.wms.http.MyHTTPProvider</BaseClass>
	<RequestFilters>helloworld*</RequestFilters>
	<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>

Place the new provider above any other providers that have a wildcard for the RequestFilters property; in other words, put it above any HTTP provider with <RequestFilters>*</RequestFilters>. Since the wildcard is a catchall for any previously unmatched request filters, anything below it in the list isn't executed.

After adding the provider, restart Wowza Streaming Engine.

Then, go to http://[wowza-ip-address]:8086/helloworld to see the information.

Useful HTTP provider calls


The following calls are useful when developing HTTP providers.

Get HTTP request URL:

String path = super.getPath(req, false);

Get HTTP request header value:

String headerValue = req.getHeader(headerName);

Set HTTP response header value:

resp.setHeader(headerName, headerValue);

Set HTTP response status:

resp.setResponseCode(404);

More resources