Let your Wowza server provide RESTful Web services

Source: Internet
Author: User
Tags log log wowza wowza server

Sometimes our nginx needs to interact with the Wowza server for some LB matters; sometimes our administrators need to know some other state information about the Wowza server in real time (such as the state of some custom objects, etc.), and rtmp is not too convenient. In these cases, it would be nice if our Wowza server could provide an HTTP API, just like the Web container tomcat. This article takes a simple http send parameter to Wowza, and then Wowza returns a JSON example (the classic REST case) that describes how to get your Wowza server to provide a RESTful Web invocation interface.
This article is further developed on the basis of the example "replace Ant: Using Maven Management Wowza plug-in development", without using Wowza's official Eclipse plugin (the official use of ant for Wowza Project management).
1. Create a new MAVEN project
Refer to "Replacing Ant: Using Maven to manage Wowza plug-in development" steps. The new MAVEN project Defonds-server-module as follows:

Debug debug effect for new project:

2. Writing the Httprovider2base subclass
Package Com.defonds.wms.module.server;import Java.io.ioexception;import Java.io.outputstream;import Com.wowza.wms.http.httprovider2base;import Com.wowza.wms.http.ihttprequest;import Com.wowza.wms.http.ihttpresponse;import Com.wowza.wms.logging.wmslogger;import Com.wowza.wms.logging.wmsloggerfactory;import Com.wowza.wms.vhost.ivhost;public class ServerMonitorHttpInterface Extends Httprovider2base {private static final Wmslogger logger = Wmsloggerfactory.getinstance (). Getloggerobj ( ServerMonitorHttpInterface.class.getName ()); @Overridepublic void Onhttprequest (Ivhost ivhost, ihttprequest request, Ihttpresponse response) {String id = request.getparameter ("id"); String name = Request.getparameter ("name"); Logger.debug ("servermonitorhttpinterface--http--request--id=" + ID + "; Name= "+ name";//TODO do your own business logic herestring jsonobject = "{\" key1\ ": \" value1\ ", \" key2\ ": \" Value2\ "}"; resp Onse.setheader ("Content-type", "Application/json");//Get the PrintWriter object from response to WRITE the required JSON object to the output stream outputstream out = Response.getoutputstream (); try {out.write (jsonob Ject.getbytes ()); Out.flush ();} catch (IOException e) {logger.error (E.getmessage (), E);}}}
3. Edit Vhost.xml
Edit%wowza%/conf/vhost.xml, add a httpprovider:
<HTTPProvider>    <baseclass>com.defonds.wms.module.server.servermonitorhttpinterface</ baseclass>    <RequestFilters>monitor*</RequestFilters>    <authenticationmethod>none </AuthenticationMethod></HTTPProvider>

4. Project Repackaging Deployment
The command line switches to your Defonds-server-module project directory and executes
MVN Package
Check the%wowza%/lib directory and discover that Defonds-server-module has been successfully deployed:

5. Access Interface
Debug starts Defonds-server-module and then accesses http://localhost:1935/monitor?id=9527&name=defonds in the browser
Found to be returning
Wowza streaming Engine 4 Trial Edition

The Eclipse console also does not have the log log servermonitorhttpinterface should be output.
This is because com.wowza.wms.http.HTTPServerVersion this httpprovider to intercept the request:

Because it's configured to be *. You can change it to something else, or comment it out. You can do it.
After commenting out httpserverversion, restart Defonds-server-module, and then access http://localhost:1935/monitor?id=9527&name=defonds:
This time we are returning the information we want:

The Eclipse console has a log output:
DEBUG Server Comment-servermonitorhttpinterface--http--request--id=9527;name=defonds
It worked. Well, that's all, that's how simple: The sample source has been uploaded CSDN, interested friends can go here to download: http://download.csdn.net/detail/defonds/7493981.
References
    • Http://stackoverflow.com/questions/10410854/call-a-wowza-server-from-android-app
    • Http://stackoverflow.com/questions/2010990/how-do-you-return-a-json-object-from-a-java-servlet
    • http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.