An Introduction to SIP, Part 2: SIP Servlets
Pages: 1, 2, 3, 4

Building, Packaging, Deploying

SIP servlets need to be compiled and then packaged into SAR files (Servlet ARchives). This is the functional equivalent of WAR files and uses the same structure. See Figure 2:

figure 2
Figure 2. SAR file structure

The last step is the deployment, which depends on your SIP application server. It usually involves copying the SAR file to a deployment folder, and then deploying the application.

Here's an Ant script to help you achieve all that:

<project name="ChatRoomServer"  default="build"  basedir=".">

    <!-- Change this to specify the name of the chat room. In order to
         send messages to this chat room, simply deploy just4fun.sar, and
         use the address sip:just4fun@ -->
    <property name="chatroomname" value="just4fun" />

    <!-- Change this to the address and port of the SIP server. -->
    <property name="serveraddress" value="" />

    <!-- Change this to the location of the SAR deployment folder. -->
    <property name="sar.deployment" value="" />

    <property name="src" value="${basedir}/src" />
    <property name="lib" value="${basedir}/lib" />
    <property name="tmp" value="${basedir}/tmp" />

    <path id="classpath">
        <fileset dir="${lib}"/>

    <target name="build">
        <mkdir dir="${tmp}"/>
        <mkdir dir="${tmp}/WEB-INF"/>
        <mkdir dir="${tmp}/WEB-INF/classes"/>
        <mkdir dir="${tmp}/WEB-INF/lib"/>
        <javac debug="true" srcdir="${src}" destdir="${tmp}/WEB-INF/classes">
            <classpath refid="classpath"/>
        <copy todir="${tmp}/WEB-INF" file="${basedir}/sip.xml"/>
        <replace file="${tmp}/WEB-INF/sip.xml" token="chatroomname" value="${chatroomname}"></replace>
        <replace file="${tmp}/WEB-INF/sip.xml" token="serveraddress" value="${serveraddress}"></replace>
        <zip destfile="${basedir}/${chatroomname}.sar">
            <zipfileset dir="${tmp}"/>
        <copy file="${basedir}/${chatroomname}.sar" todir="${sar.deployment}"/>


The Result

Once the chat room application is running, try accessing it by running two instances of the TextClient. Make sure SIP applications running on the same computer all use different ports. Below is an example showing all three applications running on the same computer:

  • SIP application server running the ChatRoomServer; the address is sip:just4fun@
  • Text client with address sip:snoopy71@
  • Text client with address sip:maria119@

Figure 3 shows the result.

figure 3
Figure 3. TextClient interacting with ChatRoomServer

Complex Applications

I bet the examples in this article are almost trivial compared to the application you would like to build. The fact is, most SIP applications consist of a lot more code than this.

Sessions and state: Usually, a SIP application is a state machine where calls or conversations are maintained (stateful) through time, until a disconnection happens. For SIP servlets, the call is represented by a SipApplicationSession, which can hold attributes (state). In a call, each dialog (leg of the call) is represented by a SipSession inside the SipApplicationSession. (A back-to-back conversation between two people would imply one SipApplicationSession and two SipSessions. A conference call would contain more SipSessions.) These can also hold attributes. The container will provide the right session objects automatically based on the message's context.

Layered design: The worst thing you can do is put all the code in a single, huge SIP servlet. You want to design your complex application in relatively independent layers. An obvious one is the database layer, including connection pooling. But you may also want to have a business logic layer separate from the SIP signaling. Another aspect is payload parsing, which should be done as a reusable layer.

Other techniques: Many advanced SIP servlet techniques exist, including request proxying, redirecting and looping, session timeout management, authentication, internationalization, TCP support, timers, session listeners, and error management. Obviously this article isn't extensive enough to cover all these subjects, but you may find information about them in the SIP Servlet specification.

Examples: See the reference section for several examples that can help you learn more complex SIP programming.


Standards promote interoperability, which promotes collaboration. And collaboration, whether for a fun chat with a friend, or for a vital file transfer, is a good thing.

SIP is an extremely promising telecommunication standard, and the SIP Servlet API is a great way to easily and rapidly develop server-side SIP applications. In this article, you have seen, via a simple example, an overview of SIP servlet programming. Hopefully it provided you with a good push in the direction of collaboration.


  • TextClient application
  • ChatRoomServer application

Additional Reading

Emmanuel Proulx is an expert in J2EE and SIP. He is a certified WebLogic Server engineer.