lundi 30 novembre 2009

Custom application router with Mobicents/Tomcat and Eclipse

Introduction

This tutorial shows how to create a custom application router, deploy it and debug inside Eclipse.
Prerequisites : follow the tutorial Developping a simple SIP application with Mobicents and Eclipse.

Create the project


The workspace can be found on the Mobicents-public google group : click here.
  • In the File menu, click new/Java project.
  • In the dialog, enter "approuter" as project name, then click Finish.
  • Edit the Java build path for the new approuter project (right click on your project, then properties/Java build path).
  • Click Add Library, Server runtime, Mobicents
  • From the package explorer, create a package org.example.servlet.sip
  • In this package, add a file called ApplicationRouter.java (right clic/new/file)
  • Cut'n'paste the following :
package org.example.servlet.sip;

import java.io.Serializable;
import java.util.List;
import java.util.Properties;

import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.ar.SipApplicationRouter;
import javax.servlet.sip.ar.SipApplicationRouterInfo;
import javax.servlet.sip.ar.SipApplicationRoutingDirective;
import javax.servlet.sip.ar.SipApplicationRoutingRegion;
import javax.servlet.sip.ar.SipRouteModifier;
import javax.servlet.sip.ar.SipTargetedRequestInfo;

public class ApplicationRouter implements SipApplicationRouter {


public SipApplicationRouterInfo getNextApplication(SipServletRequest r,
SipApplicationRoutingRegion rr,
SipApplicationRoutingDirective rd, SipTargetedRequestInfo tri,
Serializable s) {

System.out.println("**** Approuter called ****");
return new SipApplicationRouterInfo("SimpleServlet",SipApplicationRoutingRegion.ORIGINATING_REGION,r.getFrom().toString(),null,SipRouteModifier.NO_ROUTE,null);
}


public void init() {
System.out.println("**** Approuter V2 started ****");
}


public void init(Properties arg0) {
System.out.println("**** Approuter started ****");
}

public void applicationDeployed(List arg0) {
System.out.println("**** Deploy ****");
}

public void applicationUndeployed(List arg0) {

System.out.println("**** Undeploy ****");

}

public void destroy() {
System.out.println("**** Approuter destroy ****");

}

}


  • Add the file ApplicationRouterProvider.java
package org.example.servlet.sip;

import javax.servlet.sip.ar.SipApplicationRouter;
import javax.servlet.sip.ar.spi.SipApplicationRouterProvider;

public class ApplicationRouterProvider extends SipApplicationRouterProvider{

private final ApplicationRouter appRouter = new ApplicationRouter();

public ApplicationRouterProvider() {
}

public SipApplicationRouter getSipApplicationRouter() {
return appRouter;
}
}



  • Generate the approuter.jar (right clic/export/java/jar file)

Configure your server

Now, we will tell the Mobicents server running inside Eclipse to use your application router instead of the standard one.

  • In the servers pane, double clic on your server
  • Clic "Open launch configuration"
  • In the classpath tab, under "User Entries", add your approuter.jar (clic Add external jar)


  • In the "Arguments" tab, add "-Djavax.servlet.sip.ar.spi.SipApplicationRouterProvider=org.example.servlet.sip.ApplicationRouterProvider"


  • Start the server. You should see in the log file that Mobicents is actually using your custom AR.
  • Call your server with x-lite (see previous tutorial). You should get the Ringback. Check the log file "approuter used".

4 commentaires:

  1. Hi Ben,

    I've follow the previous tutorial "Developping a simple SIP application with Mobicents and Eclipse", but failed since the doInvite method of the SimpletServlet do not invoke correctly. Seems that the default application router cannot invoke the SimpleServlet. So I decided to go to this tutorial but also failed, the Tomcat running within Eclipse cannot locate the custom application router provider class.

    RépondreSupprimer
  2. I really love this blog post. It is quite informative and also rich in quality informational detail for all types of readers. I am a routine researcher and reader who reads different blog posts on a daily basis for the sake of knowledge. So as a part of readers' society, I want to pay my role in increasing the knowledge of other readers and researchers. I recently wrote a piece with the same quality of information on herbalife afresh, you can also read it. This will surely increase the knowledge and the interest of readers who regularly visit your site.

    RépondreSupprimer