Version

What are SIP Servlets

We assume that you are already familiar with the Java Servlet and its core concepts, such as request-response handling, session management, and lifecycle methods. If not, you may want to review the Java Servlet Specification before diving into SIP servlets.

A SIP servlet is a Java-based server-side component that processes Session Initiation Protocol (SIP) signaling. SIP servlets are managed by a SIP servlet container, which is typically part of a SIP-enabled application server. They enable real-time communications by handling SIP requests and responses, facilitating VoIP calls, instant messaging, and other SIP-based interactions.
Like HTTP servlets in web applications, SIP servlets provide a structured programming model for SIP applications. The SIP servlet API is designed for event-driven communication because SIP is inherently asynchronous and can generate multiple responses to a single request.

SIP Servlet Architecture

Before diving into SIP servlet functionality, let’s briefly explore the key components that make up a SIP servlet-based application.

SIP Servlet Container

SIP Servlet Container is the runtime environment that manages SIP servlets. The SIP servlet container operates within a SIP-enabled application server, providing an execution environment similar to how an HTTP servlet container runs inside a web server. It is responsible for:

  • Deploying and managing SIP servlets.
  • Routing SIP messages to the appropriate servlets.
  • Handling concurrency and asynchronous processing.
  • Managing SIP session lifecycles.

SIP-Enabled Application Server

SIP-Enabled Application Server extends traditional Java EE (Jakarta EE) servers by adding SIP support. These servers allow SIP servlets to:

  • Process real-time SIP-based communications (VoIP, messaging, etc.).
  • Integrate with other Java EE components (HTTP servlets, EJBs, web services).
  • Provide scalability and high availability for SIP applications.

Today, there are several SIP-enabled application servers, including IBM WebSphere SIP Container, Oracle Communications Application Server, Red Hat JBoss SIP Server.

SIP Clients and Endpoints

SIP servlets communicate with various types of SIP endpoints, such as softphones (Software-based SIP clients), VoIP Phones (Hardware phones that use SIP for signaling), SIP Proxies and Gateways (Intermediary servers that route SIP requests).

So how does a SIP Message Flow between these entities? We can describe a basic SIP message flow as follows:

  1. A SIP client (such as a softphone or VoIP device) sends a SIP request (e.g., INVITE).
  2. The SIP servlet container receives and processes the request.
  3. The SIP servlet generates a response or proxies the request to another SIP entity.
  4. The response is sent back to the client, completing the transaction.

Core Functionality of SIP Servlets

SIP Servlet Lifecycle

The SIP servlet lifecycle can be described as follows:

  1. Initialization (init method) – When a SIP servlet is deployed, the container calls its init method to initialize resources and perform any necessary setup before handling requests.
  2. Handling SIP Requests – Once initialized, the servlet processes incoming SIP requests and responses through doRequest and doResponse, handling message routing, proxying, or response generation as needed.
  3. Session Management – Throughout its operation, the servlet maintains and tracks SIP sessions, ensuring that interactions between clients remain consistent and properly managed.
  4. Asynchronous Event Handling – Unlike traditional synchronous processing, SIP servlets handle events asynchronously, allowing non-blocking request processing and efficient handling of multiple interactions.
  5. Destruction (destroy method) – When the servlet is no longer needed, the container calls its destroy method to release resources and perform cleanup before shutting down.

Retrieving Information in SIP Servlets

A SIP servlet requires specific data to process incoming requests, manage sessions, and make routing or authentication decisions. It can retrieve information from the following sources:

  • Initialization Parameters. SIP servlets can access configuration data defined in deployment descriptors or annotations, allowing customization of behavior without modifying code.
  • Server Information. The servlet can retrieve details about the SIP servlet container, including server properties and capabilities, to adapt its processing accordingly.
  • Client Information. Incoming SIP requests contain client-specific details, such as sender addresses and user-agent headers, which the servlet can extract for processing.
  • SIP Request Details. The servlet can access SIP request components, including headers, parameters, and message bodies, to analyze and handle incoming messages appropriately.

SIP Session Tracking

SIP servlets use session tracking to maintain state across multiple SIP transactions, but only through SIP-specific mechanisms such as SipSession and SipApplicationSession. HTTP session tracking does not apply directly. Here’s how SIP servlets track sessions:

  • Understanding SIP Sessions. SIP servlets manage two types of sessions: SipSession and SipApplicationSession. A SipSession represents a single SIP dialog between two endpoints, while a SipApplicationSession is a broader session that can group multiple SipSession instances, allowing a servlet to track interactions across multiple calls or transactions.
  • Tracking User State. SIP sessions persist across transactions, meaning a servlet can retain information about an ongoing call, message exchange, or any other SIP interaction. This allows applications to handle call transfers, multi-step authentication, or user presence tracking.
  • Event Handling. SIP session listeners enable servlets to react to session lifecycle events, such as creation, expiration, or termination. By implementing these listeners, applications can trigger custom logic when a session starts, update session data during a transaction, or clean up resources when the session ends.

Security in SIP Servlets

Security in SIP servlets ensures the integrity, confidentiality, and access control of SIP-based communications.

  • SIP Authentication. To verify client identities, SIP servlets use authentication mechanisms, where clients must provide valid credentials before processing their requests. This prevents unauthorized access and ensures that only trusted users can initiate or respond to SIP transactions.
  • Transport Security. To protect SIP messages from interception or tampering, SIP applications use Transport Layer Security (TLS) to encrypt communication between clients and servers. This secures sensitive data such as call signaling and user credentials against eavesdropping or attacks.
  • Access Control. SIP servlets can enforce role-based access control (RBAC), restricting certain SIP actions based on user permissions. This ensures that only authorized users or services can perform specific operations, such as making calls, sending messages, or modifying session parameters.

Database Connectivity in SIP Applications

SIP applications often need to interact with databases to store and retrieve relevant data. This can be achieved through the following approaches:

  • Integrating with User Databases. SIP servlets can connect to databases to manage user-related data, such as account information, call history, and SIP registration details.
  • Common Use Cases. Databases are commonly used to store contact lists, call logs, authentication records, and other persistent data required for SIP-based applications.
  • Using JDBC with SIP Servlets. SIP servlets typically use JDBC (Java Database Connectivity) to interact with relational databases, allowing them to execute queries, update records, and retrieve data for real-time communication services.

SIP Servlets vs. HTTP Servlets

Feature HTTP Servlets SIP Servlets
Context Runs within a context-root No fixed context
Communication Model Request-response, client-server Peer-to-peer, event-driven
Response Handling Returns HTML or other content Manages SIP sessions, proxies requests
Origination Cannot initiate requests Can initiate SIP requests
Concurrency Typically stateless, one response per request Can generate multiple responses per request
Asynchronous Processing Usually synchronous Fully asynchronous, event-driven
Integration Used in web applications Works with SIP-enabled clients (VoIP, softphones, etc.)


Integration with Java EE

SIP servlets can be integrated with Java EE (Jakarta EE) components, enabling the development of converged applications that combine SIP-based communication with traditional web and enterprise services. A converged application includes one or more SIP servlets along with Java EE components such as HTTP servlets, JavaServer Faces applications, enterprise beans, or web services. As a result, this integration allows these components to interact.
SIP Servlets in Converged Applications. In a converged application, SIP servlets work alongside HTTP servlets and other Java EE components to provide both real-time communication and web-based services. For example, a customer support system could allow users to initiate a voice call directly from a web interface, with the SIP servlet handling the call setup while an HTTP servlet manages the web-based interaction.
Interoperability with Java EE Components. SIP servlets can interact with various Java EE technologies to extend their functionality. They can communicate with EJBs to perform business logic operations, such as verifying user credentials before establishing a call. Additionally, they can expose or consume web services (SOAP or REST) to integrate with external systems, such as CRM platforms, billing services, or calendar applications for intelligent call routing.
SIP servlets are widely used in various situations, including:

  • Click-to-Call Applications – Users can initiate VoIP calls directly from a website, where an HTTP servlet handles the request and a SIP servlet processes the call.
  • Intelligent Call Routing – A SIP servlet can interact with a calendar system or database to route incoming calls based on an employee’s availability.
  • Multi-Channel Contact Centers – SIP servlets manage SIP-based voice interactions, while HTTP servlets handle web chat or email support within the same application.
  • Voicemail and Notification Systems – SIP servlets integrate with messaging services to send voicemail notifications via email or SMS.

SIP servlets build upon the generic servlet API defined by the Java Servlet Specification but introduce specific extensions to support SIP messaging. To learn how SIP servlets process SIP requests and integrate with other Java EE components, see our SIP Servlet API section.

Start innovating with Mobius

What's next? Let's talk!

Mobius Software

As a company you'll get:

  • Get started quickly

  • Support any business model

  • Join millions of businesses

Questions? websupport@mobius.com