Everything is ready to create a brand new application. Right click on WEB-INF/src, choose New -> Class, type com.milgra for package, Application for name, then press Finish. Our java source appeared in the editor v

This will be our main class, so we need to extend it from the ApplicationAdapter class of red5. Add red5.jar to our build path first. Project menuitem -> Properties -> Java Build Path -> Libraries -> Add External JARs, choose red5.jar in the root folder of red5. Now Eclipse can compile and tip for us.

Create appStart and appStop functions first:

package com.milgra;
import org.red5.server.adapter.ApplicationAdapter;
public class Application extends ApplicationAdapter
{
    public Boolean appStart ( )
    {

    }
    public void appStop ( )
    {

    }
}

Seeing client connections would be good, but we have to import a new class for this:

import org.red5.server.api.IConnection;

so:

public boolean appConnect( IConnection conn , Object[] params )
{
    return true;
}

public void appDisconnect( IConnection conn , Object[] params )
{

}

To debug our application we need logging, so create a logger what prints our logs to the standard output. Lets import a log and logfactory.

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

But something is wrong, because Eclipse marks this two rows with red underline, what is the problem? Eclipse doesn’t know about org.apache.commons.logging, lets add its package quickly:

Project menuitem -> Properties -> Build path -> Libraries -> Add External JARs - pick commons-logging-1.1.jar from folder red5/lib, press OK.

Log a bit:

private static final Log log = LogFactory.getLog( Application.class );

public boolean appStart ( )
{
    log.info( "Red5First.appStart" );
    return true;
}

public void appStop ( )
{
    log.info( "Red5First.appStop" );
}

public boolean appConnect( IConnection conn , Object[] params )
{
    log.info( "Red5First.appConnect " + conn.getClient().getId() );
    return true;
}

public void appDisconnect( IConnection conn , Object[] params )
{
    log.info( "Red5First.appDisconnect " + conn.getClient().getId() );
}

Only a simple demo logic is needed now, lets say if we pass true to the server at connection, we let the client in, if we pass false, we reject it.

private static final Log log = LogFactory.getLog( Application.class );

public boolean appStart ( )
{
    log.info( "Red5First.appStart" );
    return true;
}

public void appStop ( )
{
    log.info( "Red5First.appStop" );
}

public boolean appConnect( IConnection conn , Object[] params )
{
    log.info( "Red5First.appConnect " + conn.getClient().getId() );

    boolean accept = (Boolean)params[0];

    if ( !accept ) rejectClient( "you passed false..." );

    return true;
}

public void appDisconnect( IConnection conn , Object[] params )
{
    log.info( "Red5First.appDisconnect " + conn.getClient().getId() );
}

Final code will look like this:

package com.milgra;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.red5.server.api.IConnection;
import org.red5.server.adapter.ApplicationAdapter;

public class Application extends ApplicationAdapter
{
    private static final Log log = LogFactory.getLog( Application.class );

    public boolean appStart ( )
    {
        log.info( "Red5First.appStart" );
        return true;
    }

    public void appStop ( )
    {
        log.info( "Red5First.appStop" );
    }

    public boolean appConnect( IConnection conn , Object[] params )
    {
        log.info( "Red5First.appConnect " + conn.getClient().getId() );

        boolean accept = (Boolean)params[0];

        if ( !accept ) rejectClient( "you passed false..." );

        return true;
    }

    public void appDisconnect( IConnection conn , Object[] params )
    {
        log.info( "Red5First.appDisconnect " + conn.getClient().getId() );
    }
   
}

We are ready with the java code, only the configuration of the xml’s is needed. Check the four files under WEB-INF folder.

log4j.properties :

application-related logging parameters

red5-web.properties :

this file is included by red5-web.xml, constant parameters can be placed here. webapp.contextPath will be the path to our application at connection, ( not the folder name under webapps!!! ), set it to firstapp

webapp.contextPath=/firstapp
webapp.virtualHosts=localhost, 127.0.0.1

and save it.

red5-web.xml:

spring loads and configures our application based on this file. bean handlers can also be here.

Our web handler will be the Application created above, so set it as:

<bean id="web.handler"
        class="com.milgra.Application"
        singleton="true" />

And delete myhandler.service, we don’t need it now.

web.xml :

jetty will read this first. Rename the application here to firstapp, and delete the two gateway-related nodes, why use gateway when direct database connection is avaiable from java? :)

<context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>/firstapp</param-value>
    </context-param>


OK, lets Build the project. Project menuitem -> Build Automatically, so Eclipse will recompile after every modification, and that's great.

Set up our new application under red5: create a new folder under red5/webapps named firstapp ( this is what we set in red5-web.properties ), and copy here WEB-INF from EclipseWorkspace/Red5FirstApp. Then start red5 with your os-specific startup file in the root of red5, and our application is ready.