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 :
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 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
A terminology list can be found here
.
A list of known limitations and problems can be found here
Useful Sip Container related links can be found here.