Wowza Community

HTTProvider that returns detail server info

An HTTPProvider is an extension to the server that can be attached to a HostPort definition in [install-dir]/conf/VHost.xml and can be used to return HTTP data quickly from the server using a web browser or automated tool. There is more detailed information on this subject in the User’s Guide. The class below is an HTTPProvider that returns detail server information.

package com.mycompany.wms.http;
import java.io.*;
import java.util.*;
import com.wowza.wms.vhost.*;
import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.server.*;
import com.wowza.wms.application.*;
import com.wowza.wms.http.*;
import com.wowza.wms.client.*;
public class HTTPServerInfoXML implements IHTTPProvider
{
	private WMSProperties properties = null;
	private HTTPCrossdomainHandler crossdomainHandler = new HTTPCrossdomainHandler();
	
	public void onBind(IVHost vhost, HostPort hostPort)
	{
		crossdomainHandler.setVHost(vhost);
	}
	public void onUnbind(IVHost vhost, HostPort hostPort)
	{
	}
	
	public void setProperties(WMSProperties properties)
	{
		this.properties = properties;
		crossdomainHandler.setProperties(properties);
	}
	
	private void outputConnectionInfo(StringBuffer ret, ConnectionCounter counter)
	{
		ret.append("<ConnectionsCurrent>"+counter.getCurrent()+"</ConnectionsCurrent>");
		ret.append("<ConnectionsTotal>"+counter.getTotal()+"</ConnectionsTotal>");
		ret.append("<ConnectionsTotalAccepted>"+counter.getTotalAccepted()+"</ConnectionsTotalAccepted>");
		ret.append("<ConnectionsTotalRejected>"+counter.getTotalRejected()+"</ConnectionsTotalRejected>");
	}
	
	public void onHTTPRequest(IVHost inVhost, IHTTPRequest req, IHTTPResponse resp)
	{
		if (crossdomainHandler.handleCrossdomainRequest(inVhost, req, resp))
			return;
		StringBuffer ret = new StringBuffer();
		
		try
		{
			List vhostNames = VHostSingleton.getVHostNames();
			ret.append("<?xml version=\"1.0\"?>\n<WowzaMediaServerPro>");
					
			Iterator<String> iter = vhostNames.iterator();
			while (iter.hasNext())
			{
				String vhostName = iter.next();
				IVHost vhost = (IVHost)VHostSingleton.getInstance(vhostName);
				if (vhost != null)
				{
					ret.append("<VHost>");
					ret.append("<Name>"+vhostName+"</Name>");
					ret.append("<TimeRunning>"+vhost.getTimeRunningSeconds()+"</TimeRunning>");
					ret.append("<ConnectionsLimit>"+vhost.getConnectionLimit()+"</ConnectionsLimit>");
					
					outputConnectionInfo(ret, vhost.getConnectionCounter());
					
					List appNames = vhost.getApplicationNames();
					List<String> appFolders = vhost.getApplicationFolderNames();
					Iterator<String> appNameIterator = appFolders.iterator();
					while (appNameIterator.hasNext())
					{
						String applicationName = appNameIterator.next();
						ret.append("<Application>");
						ret.append("<Name><![CDATA["+applicationName+"]]></Name>");
						boolean appExists = appNames.contains(applicationName);
						ret.append("<Status>"+(appExists?"loaded":"unloaded")+"</Status>");
						if (appExists)
						{
							IApplication application = vhost.getApplication(applicationName);
							ret.append("<TimeRunning>"+application.getTimeRunningSeconds()+"</TimeRunning>");
							outputConnectionInfo(ret, application.getConnectionCounter());
							
							List appInstances = application.getAppInstanceNames();
							Iterator<String> iterAppInstances = appInstances.iterator();
							while (iterAppInstances.hasNext())
							{
								String appInstanceName = iterAppInstances.next();
								IApplicationInstance appInstance = application.getAppInstance(appInstanceName);
								if (appInstance == null)
									continue;
								
								ret.append("<ApplicationInstance>");
								ret.append("<Name><![CDATA["+appInstance.getName()+"]]></Name>");
								ret.append("<TimeRunning>"+appInstance.getTimeRunningSeconds()+"</TimeRunning>");
								
								outputConnectionInfo(ret, appInstance.getConnectionCounter());
								
								int count = appInstance.getClientCount();
								for(int c=0;c<count;c++)
								{
									IClient client = appInstance.getClient(c);
									if (client == null)
										continue;
									ret.append("<Client>");
									ret.append("<ClientId>"+client.getClientId()+"</ClientId>");
									ret.append("<FlashVersion>"+client.getFlashVer()+"</FlashVersion>");
									ret.append("<IpAddress>"+client.getIp()+"</IpAddress>");
									ret.append("<Referrer><![CDATA["+client.getReferrer()+"]]></Referrer>");
									ret.append("<TimeRunning>"+client.getTimeRunningSeconds()+"</TimeRunning>");
									//ret.append("<Duration>"+((double)(System.currentTimeMillis()-client.getConnectTime())/1000.0)+"</Duration>");
									ret.append("<DateStarted>"+client.getDateStarted()+"</DateStarted>");
									ret.append("<URI><![CDATA["+client.getUri()+"]]></URI>");
									
									String protocolStr = "unknown";
									switch(client.getProtocol())
									{
									case RtmpSessionInfo.PROTOCOL_RTMP:
										protocolStr = client.isEncrypted()?"RTMPE":"RTMP";
										break;
									case RtmpSessionInfo.PROTOCOL_RTMPT:
										protocolStr = client.isSSL()?"RTMPS":(client.isEncrypted()?"RTMPTE":"RTMPT");
										break;
									}
									
									ret.append("<Protocol>"+protocolStr+"</Protocol>");
									ret.append("<IsSSL>"+client.isSSL()+"</IsSSL>");
									ret.append("<IsEncrypted>"+client.isEncrypted()+"</IsEncrypted>");
									ret.append("<Port>"+client.getServerHostPort().getPort()+"</Port>");
									ret.append("</Client>");
								}
								
								ret.append("</ApplicationInstance>");
							}
						}
						
						ret.append("</Application>");
					}
					
					ret.append("</VHost>");
				}
			}
			
			ret.append("</WowzaMediaServerPro>");
		}
		catch (Exception e)
		{
			WMSLoggerFactory.getLogger(HTTPServerVersion.class).error("HTTPServerInfoXML.onHTTPRequest: "+e.toString());
			e.printStackTrace();
		}
				
		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("HTTPServerInfoXML.onHTTPRequest: "+e.toString());
			e.printStackTrace();
		}
	}
}

Use the Wowza IDE to compile this class into a jar file and copy it to the [install-dir]/lib folder. To use it, edit [install-dir]/conf/VHost.xml and change the HostPort/HTTPProvider/BaseClass to the full path to this class com.mycompany.wms.http.HTTPServerInfoXML.

Charlie

I’m getting ClassNotFoundException error.

error parsing HTTPProvider properties: java.lang.ClassNotFoundException: com.test.HTTPServerInfoXML

com.test.HTTPServerInfoXML

how do i verify the classpath?

If you compiled as is, it will be:

com.mycompany.wms.http.HTTPServerInfoXML

package.ClassName

Richard

Thomas,

With Wowza Server 2 Advanced you can define as many HTTPProviders as you want using “RequestFilters”:

com.wowza.wms.http.HTTPServerInfoXML

*serverinfoxml

none

com.wowza.wms.http.HTTPConnectionCountsXML

*connectioncounts.xml

none

You can get Wowza Server 2 Advanced here:

http://wowza.com/advanced

Richard

Also, with Wowza 1.7.2 you could do it by creating new HostPort/s using other ports, just for its HTTPProvider.

4

*

8080

true

24000

65000

true

100

com.wowza.wms.http.YourHTTPProvider

Richard

Works here too, thanks Charlie …

I got it working. Realized that it is a problem in my jar file (corrupted).

Exactly what I was looking for. Richard pointed me to this thread :slight_smile:

It works well, but let’s say I’d like to have different http servlets running. How to map each servlet to a url? Currently I can only have 1 httpprovider no matter which url I input, it always hits the same provider.

Hmmm… That’s not very pretty, but yeah it does the trick, as it is used only internally by my server. Thank your Richard :cool: