Let your Wowza server provide RESTful Web services

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

Sometimes we have to interact with the Wowza server to do some LB matters; sometimes our administrators need to know some of the other state information of the Wowza server in real time (for example, the state of some of their own defined objects, etc.). And rtmp is not too convenient.

These cases. It would be nice if our Wowza server could provide an HTTP API. Just like Web container tomcat. This article sends a reference to Wowza with a simple HTTP. Then Wowza returns a JSON example (the classic REST case). 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 of replacing Ant: using Maven to manage Wowza plug-in development, without using Wowza's official Eclipse plugin (the official use of ant for Wowza Project management).


        1. New maven project
        Reference replace ANT: using maven to manage Wo Wza plug-in development "step. The new MAVEN project Defonds-server-module such as the following:

        Debug Debug effects for new projects:

        2. Writing 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 once again packaged and deployed
command line to switch to your Defonds-server-module project folder, run
MVN Package
Check the%wowza%/lib folder and discover that Defonds-server-module has been successfully deployed:

5. Interview interface
Debug start Defonds-server-module, then visit 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 of its configuration is *.

Be able to change to something else, or stare it out. will be able to.


After staring out of httpserverversion. Start Defonds-server-module again, and then visit 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. is so simple: This article demonstrates the sample source code 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/

Let your Wowza server provide RESTful Web services

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.