Skip Headers
Oracle® Communications Converged Application Server Developer's Guide
Release 5.1

Part Number E27707-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

5 Overview of SIP Servlet Application Development

This chapter describes the SIP protocol, and provides a background on SIP application development using the Java programming language.

About the SIP Protocol

The session initiation protocol (SIP) is a simple network signalling protocol for creating and terminating sessions with one or more participant. The SIP protocol is designed to be independent of the underlying transport protocol, so SIP applications can run on TCP,UDP, or other lower-layer networking protocols.

Typically, the SIP protocol is used for internet telephony and multimedia distribution between two or more endpoints. For example, one person can initiate a telephone call to another person using SIP, or someone may create a conference call with many participants.

The SIP protocol was designed to be very simple, with a limited set of commands. It is also text-based, so humans can read the SIP messages passed between endpoints in a SIP session.

SIP Requests

The SIP protocol defines the following common request types:

Table 5-1 File Structure Example of Application

SIP Request Description

INVITE

Initiates a session between two participants.

ACK

The client acknowledges receiving the final message from an INVITE request.

BYE

Terminates a connection.

CANCEL

Cancels any pending actions, but does not terminate any accepted connections.

OPTIONS

Queries the server for a list of capabilities.

REGISTER

Registers the address in the To header with the server.


SIP requests are codes used to indicate the various stages in a connection between SIP-enabled entities.

SIP Responses

The SIP Protocol uses response codes similar to the HTTP protocol. Some of the common response codes are:

  • 100 (Trying)

  • 200 (OK)

  • 404 (Not found)

  • 500 (Server error)

  • 600 (Global failure)

What are SIP Servlets?

A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed via a request-response programming model. A Servlet is a Java class in Java EE that conforms to the Java Servlet API, a protocol by which a Java class may respond to requests. They are not tied to a specific client-server protocol, but are most often used with the HTTP protocol. Therefore, the word “Servlet” is often used in the meaning of “HTTP Servlet”.

A SIP servlet is a Java programming language server-side component that performs SIP signalling. SIP servlets are managed by a SIP servlet container, which typically are part of a SIP-enabled application server. SIP servlets interact with clients by responding to incoming SIP requests and returning corresponding SIP responses.

SIP servlets are built off the generic servlet API provided by the Java Servlet Specification. The SIP Servlet API is standardized as JSR289 of JCP (Java Community Process).

Note:

In this document, the term "SIP Servlet" is used to represent the API, and "SIP servlet" is used to represent an application created with the API.

Figure 5-1 Servlet API and SIP Servlet API

servlet APIs

SIP Servlets are similar to HTTP Servlets, and HTTP servlet developers can easily adapt to the programming model. The service level defined by both HTTP and SIP Servlets is very similar, allowing fro the design of applications that support both HTTP and SIP. Example 5-1 shows an example of a simple SIP servlet.

Example 5-1 SimpleSIPServlet.java

package oracle.example.simple;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;

public class SimpleSIPServlet extends SipServlet {
    protected void doMessage(SipServletRequest req)
       throws ServletException, IOException
    {
       SipServletResponse res = req.createResponse(200);
       res.send();
    }
}

Example 5-1 shows a simple SIP servlet that sends back a 200 OK response to the SIP MESSAGE request. As you can see from the list, SIP Servlet and HTTP Servlet have many things in common:

  1. Servlets must inherit the base class provided by the API. HTTP servlets must inherit HttpServlet, and SIP servlets must inherit SipServlet.

  2. Methods doXxx must be overridden and implemented. HTTP servlets have doGet/doPost methods corresponding to GET/POST methods. Similarly, SIP servlets have doXxx methods corresponding to the method name (in Example 5-1, the MESSAGE method). Application developers override and implement necessary methods.

  3. The life cycle and management methods (init, destroy) of SIP Servlet are exactly the same as HTTP Servlet. Manipulation of sessions and attributes is also the same.

  4. Although not shown in the example above, there is a deployment descriptor called sip.xml for a SIP servlet, which corresponds to web.xml. Application developers and service managers can edit this file to configure applications using multiple SIP servlets.

However, there are several differences between SIP and HTTP servlets. A major difference comes from protocols. The next section describes these differences as well as features of SIP servlets.

Differences Between HTTP Servlets and SIP Servlets

SIP servlets differ from typical HTTP servlets used in web applications in the following ways:

Differences from HTTP Servlets

This section describes differences between SIP Servlets and HTTP Servlets.

Multiple Responses

You might notice in Example 5-1 that the doMessage method has only one argument. In HTTP, a transaction consists of a pair of request and response messages, so arguments of a doXxx method specify a request (HttpServletRequest) and its response (HttpServletResponse). An application takes information such as parameters from the request to execute it, and returns its result in the body of the response.

protected void doGet(HttpServletRequest req, HttpServletResponse res)
   throws ServletException, IOException

For SIP, more than one response may be returned to a single request.

Figure 5-2 Example of Request and Response in SIP

Request and response in SIP

The above figure shows an example of a response to the INVITE request. In this example, the server sends back three responses 100, 180, and 200 to the single INVITE request. To implement such sequence, in SIP Servlet, only a request is specified in a doXxx method, and an application generates and returns necessary responses in an overridden method.

Currently, SIP Servlet defines the following doXxx methods:

protected void doInvite(SipServletRequest req);
protected void doAck(SipServletRequest req);
protected void doOptions(SipServletRequest req);
protected void doBye(SipServletRequest req);
protected void doCancel(SipServletRequest req);
protected void doSubscribe(SipServletRequest req);
protected void doNotify(SipServletRequest req);
protected void doMessage(SipServletRequest req);
protected void doInfo(SipServletRequest req);
protected void doPrack(SipServletRequest req);

Receiving Responses

One of the major features of SIP is that roles of a client and server are not fixed. In HTTP, Web browsers always send HTTP requests and receive HTTP responses: They never receive HTTP requests and send HTTP responses. In SIP, however, each terminal needs to have functions of both a client and server.

For example, both of two SIP phones must call to the other and disconnect the call.

Figure 5-3 Relationship between Client and Server in SIP

Client and server in SIP

Figure 5-3 indicates that a calling or disconnecting terminal acts as a client. In SIP, roles of a client and server can be changed in one dialog. This client function is called UAC (User Agent Client) and server function is called UAS (User Agent Server), and the terminal is called UA (User Agent). SIP Servlet defines methods to receive responses as well as requests.

protected void doProvisionalResponse(SipServletResponse res);
protected void doSuccessResponse(SipServletResponse res);
protected void doRedirectResponse(SipServletResponse res);
protected void doErrorResponse(SipServletResponse res);

These doXxx response methods are not the method name of the request. They are named by the type of the response as follows:

  • doProvisionalResponse: A method invoked on the receipt of a provisional response (or 1xx response).

  • doSuccessResponse: A method invoked on the receipt of a success response.

  • doRedirectResponse: A method invoked on the receipt of a redirect response.

  • doErrorResponse: A method invoked on the receipt of an error response (or 4xx, 5xx, 6xx responses).

The use of methods to receive responses indicates that the SIP Servlet requests and responses are independently transmitted by the application using different threads. Applications must explicitly manage the association of SIP messages. The use of independent requests and responses makes the process more complicated, but enables you to write more flexible processes.

Also, SIP Servlet allows applications to explicitly create requests. Using these functions, SIP servlets not only wait for requests as a server (UAS), but also send requests as a client (UAC).

Proxy Functions

Another function that is different from the HTTP protocol is forking. Forking is a process of proxying one request to multiple servers simultaneously (or sequentially) and used when multiple terminals (operators) are associated with one telephone number (such as in a call center).

Figure 5-4 Proxy Forking

Proxy forking

SIP Servlet provides a utility to proxy SIP requests for applications that have proxy functions.

Message Body

As Figure 5-5 illustrates, the contents of SIP messages is the same as the contents of HTTP messages. Both SIP and HTTP messages include:

  • Starting line: Identifies the message as a request or a response. The starting line is also referred to as the initial request line or the initial response line.

  • Header field: Provides information about the request or response.

  • Separator: A blank line separating the header field from the message body.

  • Message body: A message may have a body of data sent after the header lines. In a response, this is where the requested resource is returned to the client (the most common use of the message body).

Figure 5-5 SIP Message Example

Description of Figure 5-5 follows
Description of "Figure 5-5 SIP Message Example"

HTTP is a protocol that transfers HTML files, images, and multimedia data. Contents to be transferred are stored in the message body. HTTP Servlet defines a stream manipulation-based API that enables the sending and receiving of these large-file content types.

Servlet Request

ServletInputStream getInputStream()
BufferedReader     getReader()

Servlet Response

ServletOutputStream getOutputStream()
PrintWriter         getWriter()
int  getBufferSize()
void setBufferSize(int size)
void resetBuffer()
void flushBuffer()

In SIP, however, only low-volume contents are stored in the message body since SIP is intended for real-time communication. Therefore, above methods are provided only for compatibility, and their functions are disabled.

In SIP, contents stored in the body include:

  • SDP (Session Description Protocol): A protocol to define multimedia sessions used between terminals. This protocol is defined in RFC2373.

  • Presence Information: A message that describes presence information defined in CPIM.

  • IM Messages: IM (instant message) body. User-input messages are stored in the message body.

Since the message body is in a small size, processing it in a streaming way increases overhead. SIP Servlet re-defines API to manipulate the message body on memory as follows:

SipServletMessage

void   setContent(Object content, String contentType)
Object getContent()
byte[] getRawContent()

Role of a Servlet Container

The following sections describe major functions provided by Converged Application Server as a SIP servlet container:

  • Application Management: Describes functions such as application management by servlet context, life cycle management of servlets, application initialization by deployment descriptors.

  • SIP Messaging: Describes functions of parsing incoming SIP messages and delivering to appropriate SIP servlets, sending messages created by SIP servlets to appropriate UAS, and automatically setting SIP header fields.

  • Utility Functions: Describes functions such as sessions, factories, and proxying that are available in SIP servlets.

Application Management

Like HTTP servlet containers, SIP servlet containers manage applications by servlet context (see Figure 5-6). Servlet contexts (applications) are normally archived in a WAR format and deployed in each application server.

Note:

The method of deploying in application servers varies depending on your product. Refer to the documentation of your application server.

Figure 5-6 Servlet Container and Servlet Context

Servlet and SIP context

A servlet context for a converged SIP and Web application can include multiple SIP servlets, HTTP servlets, and JSPs.

Converged application Server can deploy applications using the same method as the application server you use as the platform. However, if you deploy applications including SIP servlets, you need a SIP specific deployment descriptor (sip.xml) defined by SIP servlets. The table below shows the file structure of a general converged SIP and Web application.

Table 5-2 File Structure Example of Application

File Description

WEB-INF/

Place your configuration and executable files of your converged SIP and Web application in the directory. You cannot directly refer to files in this directory on Web (servlets can do this).

WEB-INF/web.xml

The Java EE standard configuration file for the Web application.

WEB-INF/sip.xml

The SIP Servlet-defined configuration files for the SIP application.

WEB-INF/classes/

Store compiled class files in the directory. You can store both HTTP and SIP servlets in this directory.

WEB-INF/lib/

Store class files archived as Jar files in the directory. You can store both HTTP and SIP servlets in this directory.

*.jsp, *.jpg

Files comprising the Web application (for example JSP) can be deployed in the same way as Java EE.


Information specified in the sip.xml file is similar to that in the web.xml except servlet-mapping setting that is different from HTTP servlets. In HTTP you specify a servlet associated with the file name portion of URL. But SIP has no concept of the file name. You set filter conditions using URI or the header field of a SIP request. The following example shows that a SIP servlet called registrar is assigned all REGISTER methods.

Example 5-2 Filter Condition Example of sip.xml

<servlet-mapping>
   <servlet-name>registrar</servlet-name>
   <pattern>
     <equal>
       <var>request.method</var>
       <value>REGISTER</value>
     </equal>
   </pattern>
 </servlet-mapping>

Once deployed, life cycle of the servlet context is maintained by the servlet container. Although the servlet context is normally started and shutdown when the server is started and shutdown, the system administrator can explicitly start, stop, and reload the servlet context.

SIP Messaging

SIP messaging functions provided by a SIP servlet container are classified under the following types:

  • Parsing received SIP messages.

  • Delivering parsed messages to the appropriate SIP servlet.

  • Sending SIP servlet-generated messages to the appropriate UA

  • Automatically generating a response (such as “100 Trying”).

  • Automatically managing the SIP header field.

All SIP messages that a SIP servlet handles are represented as a SipServletRequest or SipServletResponse object. A received message is first parsed by the parser and then translated to one of these objects and sent to the SIP servlet container.

A SIP servlet container receives the following three types of SIP messages, for each of which you determine a target servlet.

  • First SIP Request: When the SIP servlet container received a request that does not belong to any SIP session, it uses filter conditions in the sip.xml file (described in the previous section) to determine the target SIP servlet. Since the container creates a new SIP session when the initial request is delivered, any SIP requests received after that point are considered as subsequent requests.

    Note:

    Filtering should be done carefully. In Oracle Communications Converged Application Server, when the received SIP message matches multiple SIP servlets, it is delivered only to any one SIP servlet.

    The use of additional criteria such as request parameters can be used to direct a request to a servlet.

  • Subsequent SIP Request: When the SIP Servlet container receives a request that belongs to any SIP session, it delivers the request to a SIP Servlet associated with that session. Whether the request belongs to a session or not is determined using dialog ID.

    Each time a SIP Servlet processes messages, a lock is established by the container on the call ID. If a SIP Servlet is currently processing earlier requests for the same call ID when subsequent requests are received, the SIP Servlet container queues the subsequent requests. The queued messages are processed only after the Servlet has finished processing the initial message and has returned control to the SIP Servlet container.

    This concurrency control is guaranteed both in a single containers and in clustered environments. Application developers can code applications with the understanding that only one message for any particular call ID gets processed at a given time.

  • SIP Response: When the received response is to a request that a SIP servlet proxied, the response is automatically delivered to the same servlet since its SIP session had been determined. When a SIP servlet sends its own request, you must first specify a servlet that receives a response in the SIP session. For example, if the SIP servlet sending a request also receives the response, the following handler setting must be specified in the SIP session.

    SipServletRequest req = getSipFactory().createRequest(appSession, ...);
    req.getSession().setHandler(getServletName());
    

    Normally, in SIP a session means a real-time session by RTP/RTSP. On the other hand, in HTTP Servlet a session refers to a way of relating multiple HTTP transactions. In this document, session-related terms are defined as follows:

Table 5-3 Session-Related Terminology

Session Name Description

Realtime Session

A realtime session established by RTP/RTSP.

HTTP Session

A session defined by HTTP Servlet. A means of relating multiple HTTP transactions.

SIP Session

A means of implementing the same concept as in HTTP session in SIP. SIP (RFC3261) has a similar concept of "dialog," but in this document this is treated as a different term since its lifecycle and generation conditions are different.

Application Session

A means for applications using multiple protocols and dialogs to associate multiple HTTP sessions and SIP sessions. Also called "AP session."


Converged Application Server automatically execute the following response and retransmission processes:

  • Sending “100 Trying”: When Converged Application Server receives an INVITE request, it automatically creates and sends “100 Trying.”

  • Response to CANCEL: When WebLogic Communications Server receives a CANCEL request, it executes the following processes if the request is valid.

    1. Sends a 200 response to the CANCEL request.

    2. Sends a 487 response to the INVITE request to be cancelled.

    3. Invokes a doCancel method on the SIP servlet. This allows the application to abort the process within the doCancel method, eliminating the need for explicitly sending back a response.

  • Sends ACK to an error response to INVITE: When a 4xx, 5xx, or 6xx response is returned for INVITE that were sent by a SIP servlet, WebLogic Communications Server automatically creates and sends ACK. This is because ACK is required only for a SIP sequence, and the SIP servlet does not require it.

    When the SIP servlet sends a 4xx, 5xx, or 6xx response to INVITE, it never receives ACK for the response.

  • Retransmission process when using UDP: SIP defines that sent messages are retransmitted when low-trust transport including UDP is used. WebLogic Communications Server automatically do the retransmission process according to the specification.

Applications typically do not need to explicitly set and see header fields in HTTP Servlet, as HTTP Servlet containers automatically manage fields such as Content-Length and Content-Type. SIP Servlet provides the same header management functions.

In SIP, however, since important information about message delivery exists in some fields, these headers are not allowed to change by applications. Headers that can not be changed by SIP Servlets are called system headers. Table 5-4 below lists system headers:

Table 5-4 System Headers

Header Name Description

Call-ID

Contains ID information to associate multiple SIP messages as Call.

From, To

Contains Information on the sender and receiver of the SIP request (SIP, URI, etc.). tag parameters are given by the servlet container.

CSeq

Contains sequence numbers and method names.

Via

Contains a list of servers the SIP message passed through. This is used when you want to keep track of the path to send a response to the request.

Record-Route, Route

Used when the proxy server mediates subsequent requests.

Contact

Contains network information (such as IP address and port number) that is used for direct communication between terminals. For a REGISTER message, 3xx, or 485 response, this is not considered as the system header and SIP servlets can directly edit the information.


Utility Functions

SIP Servlet defines the following utilities, which are available to SIP servlets:

  1. SIP Session, Application Session

  2. SIP Factory

  3. Proxy

SIP Session, Application Session

As stated before, SIP Servlet provides a “SIP session” whose concept is the same as a HTTP session. In HTTP, multiple transactions are associated using information like Cookie. In SIP, this association is done with header information (Call-ID and tag parameters in From and To). Servlet containers maintain and manage SIP sessions. Messages within the same dialog can refer to the same SIP session. Also, For a method that does not create a dialog (such as MESSAGE), messages can be managed as a session if they have the same header information.

SIP Servlet has a concept of an “application session,” which does not exist in HTTP Servlet. An application session is an object to associate and manage multiple SIP sessions and HTTP sessions. It is suitable for applications such as B2BUA.

SIP Factory

A SIP factory (SipFactory) is a factory class to create SIP Servlet-specific objects necessary for application execution. You can generate the following objects:

Table 5-5 Objects Generated with SipFactory

Class Name Description

URI, SipURI, Address

Can generate address information including SIP URI from String.

SipApplicationSession

Creates a new application session. It is invoked when a SIP servlet starts a new SIP signal process.

SipServletRequest

Used when a SIP servlet acts as UAC to create a request. Such requests can not be sent with Proxy.proxyTo. They must be sent with SipServletRequest.send.


SipFactory is located in the servlet context attribute under the default name. You can take this with the following code.

ServletContext context = getServletContext();
SipFactory factory =
    (SipFactory) context.getAttribute("javax.servlet.sip.SipFactory");
Proxy

Proxy is a utility used by a SIP servlet to proxy a request. In SIP, proxying has its own sequences including forking. You can specify the following settings in proxying with Proxy:

  • Recursive routing (recursive): When the destination of proxying returns a 3xx response, the request is proxied to the specified target.

  • Record-Route setting: Sets a Record-Route header in the specified request.

  • Parallel/Sequential (parallel): Determines whether forking is executed in parallel or sequentially.

  • stateful: Determines whether proxying is transaction stateful. This parameter is not relevant because stateless proxy mode is deprecated in JSR289.

  • Supervising mode: In the event of the state change of proxying (response receipts), an application reports this.