SIP Servlet LifeCycle and methods

From Wesip

From Wesip

 Servlet Lifecycle

The container manages the lifecycle of the servlets. When an application is loaded the servlets marked as load-on-startup are initialized. Initialization of servlets not marked as load-on-startup is delayed until the servlet is required to process an incoming message. In the initialization process the container calls the init method of the servlet passing a ServletConfig object that stores any required initialization parameters.

Upon initialization the servlet is ready to serve incoming messages. When a message arrives the container finds a suitable servlet as per the application deployment information and the calls its service method in a new thread. Only one instance of the servlet is loaded at a time but the service method is called multiple times so developers should take into account concurrency issues.

The service method accepts two parameters which are a SipServletRequest and a SipServletResponse. One of them is always null. If the message being processed is a request SipServletResponse is null and viceversa. The service method finds out which kind of message is dealing with and then calls to doRequest or doResponse passing the request or response to be processed. doRequest and doResponse map as well to the most appropriate method as per the following chart

 SipServlet message methods

Developers decide which methods will override their servlets. There's no need to override every method but only those that are going to be needed. Overriding the methods doService, doRequest or doResponse requires a final call to the respective super method.

Finally when the servlet application is unloaded due to removal, upgrade or container shutdown the method destroy is invoked by the container to give a chance to the servlet to clean up any resources being used like database connections or files.

<< SIP Servlet Abstractions | Sessions >>