How to invoke an external URL to notify events like onPlay, onDescribe, onTearDown.

Hi,

How can i invoke an external URL (over http to notify the events) during various events like onPlay, onPause, onTearDown(), onDescribe, onAnounce() etc. Please share me a module code snippet.

Thanks in Advance.

Hi,

Use the org.apache.http.client.HttpClient. Make sure you use the correct version of the library, as Wowza uses this library too, and using a different version than Wowza does, will cause a conflict. If I’m correct, it’s version 3.1 you must use (at least that version works for me).

String url = "http://my.external.url";
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
// You can use com.google.gson.Gson to send JSON formatted data to your server
Gson gson = new Gson();
String json = gson.toJson(myObjectWithSerializableData);
StringEntity params = new StringEntity(json);
request.addHeader("content-type", "application/x-www-form-urlencoded");
request.setEntity(params);
HttpResponse response = client.execute(request);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
String data = "";
while ((line = reader.readLine()) != null) {
    data += line;
}
// Parse the response to an object, assumed that you get a response, and that it's JSON formatted
MyResponseObject respObj = gson.fromJson(data, MyResponseObject.class);

This is a synchronous call, so the HttpClient.execute will block and wait for response, so yes, the HttpResponse will always correspond to the HttpPost request.

Hi karelboek,

Thanks a lot for your response. I still have a small concern. If i have n number of RTSP sessions simultaneously, does the above code work. My concern is the stream which has invoked the http url should able to get the corresponding response. Will it work ?