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