SIP servlets
A SIP servlet is a Java-based application component managed by a SIP servlet container and that performs SIP signaling. SIP servlets interact with clients by exchanging request and response messages through the servlet container.
The SIP Servlet 1.0 specification ( JSR 116) is standardized through Java Specification Request (JSR) 116. The idea behind the specification is to provide a Java API similar to HTTP servlets, which provides an easy-to-use SIP programming model. Like the popular HTTP servlet programming model, some flexibility is limited to optimize ease-of-use and time-to-value.
However, the SIP Servlet API is different in many ways from HTTP servlets because the protocol is so different. While SIP is a request-response protocol, there is not necessarily only one response to every one request. This complexity and a need for a high performing solution meant that it was easier to make the SIP servlets natively asynchronous. Also, unlike HTTP servlets, the programming model for SIP servlets sought to make client requests easy to create alongside the other logic being written because many applications act as a client or proxy to other servers or proxies.
SipServlet requests
Like HTTP servlets, each SIP servlet extends a base javax.servlet.sip.SipServlet class. All messages come in through the service method, which we can extend. However, because there is not a one-to-one mapping of requests to responses in SIP, the suggested practice is to extend the doRequest or doResponse methods instead. When extending the doRequest or doResponse methods, it is important to call the extended method for the processing to complete.
Each request method, which the specification must support, has a doxxx method just like HTTP. In HTTP, methods such as doGet and doPost exist for GET and POST requests. In SIP, doInvite, doAck, doOptions, doBye, doCancel, doRegister, doSubscribe, doNotify, doMessage, doInfo, and doPrack methods exist for each SIP request method.
Unlike an HTTP servlet, SIP servlets have methods for each of the response types supported. So, SIP servlets include the doProvisionalResponse, doSuccessResponse, doRedirectResponse, and doErrorResponse responses. Specifically, the provisional responses (1xx responses) are used to indicate status, the success responses (2xx responses) are used to indicate a successful completion of the transaction, the redirect responses (3xx responses) are used to redirect the client to a moved resource or entity, and the error responses (4xx, 5xx, and 6xx responses) are used to indicate a failure or a specific error condition. These types of response messages are similar to HTTP, but because the SIP Servlet programming model includes a client programming model, it is necessary to have responses handled programmatically as well.
Clarifications of JSR 116
JSR 289 has made some clarifications to JSR 116, as follows:
- JSR 289 Section 4.1.3: Contact Header Field
- JSR 289 Section 5.2: Implicit Transaction State
- JSR 289 Section 5.8: Accessibility of SIP Servlet Messages
Subtopics
- SIP SipServletRequest and SipServletResponse classes
The SipServletRequest and SipServletResponse classes are similar to the HttpServletRequest and HttpServletResponse classes.- SIP SipSession and SipApplicationSession classes
Possibly the most complex portions of the SIP Servlet 1.0 specification are the SipSession and SipApplicationSession classes.- Example: SIP servlet simple proxy
This is a servlet example of a simple proxy.- Example: SIP servlet SendOnServlet class
The SendOnServlet class is a simple SIP servlet that would perform the basic function of being called on each INVITE and sending the request on from there.- Example: SIP servlet Proxy servlet class
- JSR 289 overview
v9.0 includes support for SIP Servlet Specification 1.1, also referred to as Java Specification Request (JSR) 289.
Browse all SIP topics