Home Index Changes Prefs Log in »
This is version 21. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

The Sip Servlet Proxy example

This example shows how to create a simple SIP proxy servlet. The proxy will just forward all SIP messages from SIP caller (UAC) to SIP callee (UAS). In order to test this code you may use sipp SIP generator.

The servlet code :

package com.ericsson.sip.servlet.example;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.sip.Proxy;
import javax.servlet.sip.SipErrorEvent;
import javax.servlet.sip.SipErrorListener;
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;



public class SimpleProxyServlet 
            extends SipServlet 
            implements SipErrorListener,Servlet {
    
    /** Creates a new instance of SimpleProxyServlet */
    public SimpleProxyServlet() {
    }
    
    
    protected void doInvite(SipServletRequest request) 
        throws ServletException, IOException {
    	 
        if (request.isInitial()) {

           Proxy proxy = request.getProxy();
           proxy.setRecordRoute(true);
	   proxy.setSupervised(true);
	   proxy.proxyTo(request.getRequestURI()); // bobs uri
          
        }
        
        System.out.println("SimpleProxyServlet: Got request:\n" + request);
    }
    
    
    protected void doBye(SipServletRequest request) throws ServletException, IOException {
        
        System.out.println("SimpleProxyServlet: Got BYE request:\n" + request);
        super.doBye(request);
    }
    
    
    protected void doResponse(SipServletResponse response) 
        throws ServletException, IOException {
        
        System.out.println("SimpleProxyServlet: Got response:\n" + response);
 	super.doResponse(response);
    }
    
    
    // SipErrorListener
    
    public void noAckReceived(SipErrorEvent ee) {
         
        System.out.println("SimpleProxyServlet: Error: noAckReceived.");
    }
    
    public void noPrackReceived(SipErrorEvent ee) {
        
	System.out.println("SimpleProxyServlet: Error: noPrackReceived.");
    }
    
}

Archives for Sip Servlets must be of type .sar. In this case the archive can be called sip-proxy.sar. Sip Servlet archives must also contain a deployment descriptor called sip.xml, in the WEB-INF archive directory.

sip-proxy
|-- WEB-INF
|   |-- classes
|   |   |-- com
|   |       |-- ericsson
|   |           |-- sip
|   |               |-- examples
|   |                   |-- SimpleProxyServlet.class
|   |-- lib
|   |-- sip.xml

Here is a deployment descriptor for this example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sip-app PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN" "http://www.jcp.org/dtd/sip-app_1_0.dtd">
<!-- Some documentation needed here -->

<sip-app>
    <display-name>Simple Proxy Servlet</display-name>
    <description>Simple Proxy Servlet</description>

    <servlet>
        <servlet-name>SimpleProxyServlet</servlet-name>
        <display-name>SimpleProxyServlet</display-name>
        <description>Simple SIP proxy servlet</description>
        <servlet-class>com.ericsson.sip.servlet.example.SimpleProxyServlet</servlet-class>
     	<load-on-startup>1</load-on-startup>     
    </servlet>
    
    <servlet-mapping>
    <servlet-name>SimpleProxyServlet</servlet-name>
    <pattern>
	<and>
        <equal><var>request.method</var><value>INVITE</value></equal>
	</and>
    </pattern>
  </servlet-mapping>
  
  <listener>
      <listener-class>com.ericsson.sip.servlet.example.SimpleProxyServlet</listener-class>
  </listener>
</sip-app>

To test the proxy, we will use sipp generator. SIPp is a free Open Source test tool / traffic generator for the SIP protocol. It can be downloaded from :

http://sipp.sourceforge.net/

In this test, we asume that :

  • the SIP proxy runs on a glassfish application server on a host with ip address 192.168.1.2
  • the SIP client (UAC) runs on a host with ip address 192.168.1.5 and accepts responses on port 5080
  • the SIP server (UAS) runs on a host with ip address 192.168.1.8 and accepts requests on port 5090

To run the test :

1) Build and deploy the SIP proxy

2) Start the SIP server (UAS) on the host with ip address 192.168.1.8 and port 5090 :

>> sipp -sn uas -p 5090

3) Start the SIP client (UAC) on the host with ip address 192.168.1.5 and port 5080. All traffic between SIP client and server will pass through the proxy (-rsa flag) :

>> sipp -sn uac -rsa 192.168.1.2:5060 -p 5080 192.168.1.8:5090

4) Check the message flow on the text screens of SIP client and server and on sip.log

Comments:

  • Choosing three different addresses is just to make everything more visual. It can also be run on a single machine.

List of terms

A terminology list can be found here.

Having trouble to run the demo ?

A list of known limitations and problems can be found here

Links page

Useful Sip Container related links can be found here.

« Home Attachments Info Index Changes Prefs
This particular version was published on 11-May-07 02:24 AM, -0700 by Babbis