• How to create an HTTP Provider

    HTTP Providers are Java classes that are configured on a per-virtual host basis. They are intended to be light-weight HTTP web applications that can be used to send information to or obtain information from your Wowza media server instance. This article describes how to create an HTTP Provider and includes some examples for various use cases. This article is aimed for developers that are just starting to create Wowza media server modules.

    Contents


    Introduction
    Requirements
    Creating an HTTP Provider
    Configuration
    More resources

    Introduction


    HTTP Providers are mini HTTP web applications that can be used to extend Wowza media server software 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 your Wowza Streaming Engine instance.

    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 pre-packaged with Wowza media server software:

    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.

    Requirements


    You'll need the Wowza™ IDE for Eclipse, available through our Developers webpage. To set up your IDE, see How to extend Wowza Streaming Engine using the Wowza IDE.

    Creating an HTTP Provider


    Each HTTP Provider extends the HTTProvider2Base as follows:
    class MyHTTPProvider implements 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();
    		}
    		
    	}
    }

    Configuration


    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 your Wowza media server instance. You can then access the module via the following URL:

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

    More resources


    Two common elements when developing an HTTP Provider are to handle POST/GET variables and adding HTML markup/images.

    For more information about how to handle Request parameters, see How to parse post or get variables in an HTTP Provider.

    For more information about how to handle external HTML and graphics, see How to make an HTML page with graphics and scripts using an HTTP Provider .

    Originally Published: 09-22-2015.
    Updated: for Wowza Streaming Engine 4.5.0 on 06-23-2016.

    If you're having problems or want to discuss this article, post in our forum.