I have the code below which performs an http POST within the onWriteComplete handler. I would like to remove the hard coded callback URL.
- What would be the recommended approach for this?
I need to pass this url at the start of the process e.g. on connect or on publish as I need to ensure the http post is still made if the user disconnects unintentionally e.g. browser close, crash, etc.
-
Is it best to pass the url (from Flash) using a param onConnect and store on app instance WMSProperties (I find that the property is always null within the onWriteComplete handler)?
-
Can I pass the url (from Flash) on publish and store on the stream WMSProperties (I cannot see a params argument onPublish)?
-
Can anyone post a suggestion with thread safe code?
Finally I would like to increase the security a notch by setting up authentication for the callback.
- How would I go about implementing Proxy-Authorization using setRequestProperty. For example I use this with curl
curl --data "foo=bar" "http://example.com/api/stream/processed" -u "username:password"
. What would be the recommended approach with HTTPUtils?
Thanks in advance.
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.module.ModuleBase;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaWriterActionNotify;
import com.wowza.util.HTTPUtils;
import java.io.File;
import java.util.Map;
public class MediaWriteListener extends ModuleBase {
class WriteListener implements IMediaWriterActionNotify {
public void onFLVAddMetadata(IMediaStream stream, Map<String, Object> extraMetadata){}
public void onWriteComplete(IMediaStream stream, File file) {
getLogger().info("ModuleWriteListener.onWriteComplete[" + stream.getContextStr() + "]: " + file.getName());
String callbackUrl = "http://example.com/api/stream/processed";
HTTPUtils.HTTPRequestToByteArray(callbackUrl, "POST", "id=" + file.getName() + "&state=finished", null);
}
}
public void onAppStart(IApplicationInstance appInstance) {
appInstance.addMediaWriterListener(new WriteListener());
}
}