Create a Wowza Streaming Engine HTTP provider

HTTP providers are Java classes that are configured on a per-virtual host basis. They are lightweight HTTP web applications that can send information to or obtain information from a Wowza Streaming Engine™ media server software instance. This article describes how to create an HTTP provider and includes some examples on how to use one. This article is aimed for developers who are just starting to create Wowza Streaming Engine modules.

Introduction


HTTP providers are mini HTTP web applications that can be used to extend Wowza Streaming Engine functionality. They are configured on a per-port basis in [install-dir]/conf/VHost.xml. An individual HTTP provider can be protected by a user name and password. Multiple HTTP providers can be attached to a single port and a specific HTTP provider can be selected based on a request filter. HTTP providers can also host WebSocket sessions for sending asynchronous, bi-directional information to and from Wowza Streaming Engine.

Note: Wowza Streaming Engine 4.5.0 is required for HTTP providers to support WebSocket sessions. For more information, see How to create a WebSocket server.

The following HTTP providers come with Wowza Streaming Engine:

HTTPClientAccessPolicy - (com.wowza.wms.http.HTTPClientAccessPolicy)
Serves up the Microsoft Silverlight clientaccesspolicy.xml file when present in the [install-dir]/conf folder.

HTTPConnectionCountsXML - (com.wowza.wms.http.HTTPConnectionCountsXML) Returns connection information in XML format and is available through administrative port 8086 (http://[wowza-ip-address]:8086/connectioncounts).

HTTPConnectionInfo - (com.wowza.wms.http.HTTPConnectionInfo)
Returns detailed connection information in XML format and is available through administrative port 8086 (http://[wowza-ip-address]:8086/connectioninfo).

HTTPCrossdomain - (com.wowza.wms.http.HTTPCrossdomain)
Serves up the Adobe Flash crossdomain.xml file when present in the [install-dir]/conf folder.

HTTPLiveStreamRecord - (com.wowza.wms.livestreamrecord.http.HTTPLiveStreamRecord)
Serves up the Live Stream Record web-based user interface that's available through administrative port 8086 (http://[wowza-ip-address]:8086/livestreamrecord).

HTTPProviderMediaList - (com.wowza.wms.http.HTTPProviderMediaList) Dynamic method for generating adaptive bitrate manifests and playlists from SMIL data.

HTTPServerInfoXML - (com.wowza.wms.http.HTTPServerInfoXML)
Returns detailed server and connection information in XML format and is available through administrative port 8086 (http://[wowza-ip-address]:8086/serverinfo).

HTTPServerVersion - (com.wowza.wms.http.HTTPServerVersion)
Returns the Wowza Media Server version and build number. It's the default HTTP Provider on port 1935.

HTTPStreamManager - (com.wowza.wms.http.streammanager.HTTPStreamManager)
The Stream Manager HTTP Provider that's available through administrative port 8086 (http://[wowza-ip-address]:8086/streammanager).

HTTPTranscoderThumbnail - (com.wowza.wms.transcoder.httpprovider.HTTPTranscoderThumbnail)
Returns a bitmap image from the source stream being transcoded. Available through administrative port 8086 (http://[wowza-ip-address]:8086/transcoderthumbnail?application=[application-name]&streamname=[stream-name]&format=[jpeg or png]&size=[widthxheight])

By developing an HTTP provider, you obtain the ability to view information from your own specified URL. For example:

http://[your-wowza-ip-address]:8086/[your-provider]

And your provider could return information regarding your specified instance.

Prerequisites


You'll need the Wowza™ IDE for Eclipse. See Extend Wowza Streaming Engine using the Wowza IDE.

Create an HTTP provider


Each HTTP provider extends the HTTProvider2Base as follows:

class MyHTTPProvider extends HTTProvider2Base

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) {}

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

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

		StringBuffer ret = new StringBuffer();
		ret.append("<?xml version="1.0"?>
<WowzaMediaServer>");
                ret.append("<output>Hello World!</output>");
                ret.append("</WowzaMediaServer>");
		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 an HTTP provider


After you've successfully compiled and run your HTTP provider, you can set your JAR file in the [install-dir]/lib folder and add your module to the VHost.xml file under HostPort 8086 section as follows:

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

Your configuration must be placed above any existing HTTP providers that have a wildcard for the RequestFilter element (ex. <RequestFilters>*</RequestFilters>). Since this wildcard acts as a catchall for any previously unmatched request filters, anything placed below it will not be executed.

After adding the module, restart Wowza Streaming Engine. You can then access the module via the following URL:

http://[your-wowza-ip-address]:8086/helloworld

More resources