Home Index Changes Prefs Log in »
This is version 1. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]
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 ( http://sipp.sourceforge.net/ ).

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."); } }

The deployment descriptor :

Simple Proxy Servlet Simple Proxy Servlet

SimpleProxyServlet SimpleProxyServlet Simple SIP proxy servlet com.ericsson.sip.servlet.example.SimpleProxyServlet 1 SimpleProxyServlet request.methodINVITE com.ericsson.sip.servlet.example.SimpleProxyServlet

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 beteen 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.

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