Sun GlassFish Communications Server 2.0 Developer's Guide

Request Handling

When a request is made, the Communications Server hands the incoming data to the servlet engine. The servlet engine processes the request’s input data, such as form data, cookies, session information, and URL name-value pairs, into an HttpServletRequest or SipServletRequest request object type.

The servlet engine also creates an HttpServletResponse or SipServletResponse response object type. The engine then passes both as parameters to the servlet’s service() method.

In an HTTP servlet, the default service() method routes requests to another method based on the HTTP transfer method: POST, GET, DELETE, HEAD, OPTIONS, PUT, or TRACE. For example, HTTP POST requests are sent to the doPost() method, HTTP GET requests are sent to the doGet() method, and so on. This enables the servlet to process request data differently, depending on which transfer method is used. Since the routing takes place in the service method, you generally do not override service() in an HTTP servlet. Instead, override doGet(), doPost(), and so on, depending on the request type you expect.

To perform the tasks to answer a request, override the service() method for generic servlets, and the doGet() or doPost() methods for HTTP servlets. Very often, this means accessing EJB components to perform business transactions, then collating the information in the request object or in a JDBC ResultSet object.

The service() method of javax.servlet.sip.SipServlet takes both a SipServletRequest and a SipServletResponse argument, but for every invocation of this method, only one argument is valid (different from null), depending on whether the incoming SIP message is a request or a response. If the incoming SIP message is a request, only the SipServletRequest argument is valid, and the SipServletResponse argument is null. If the incoming SIP message is a response, only the SipServletResponse argument is valid, and the SipServletRequest argument is null.

The default implementation of the service() method of javax.servlet.sip.SipServlet dispatches SIP requests to the appropriate doXXX() method (based on the SIP request method), and SIP responses to the appropriate doXXXResponse() method (based on the SIP response status code). The doXXX() methods take a single argument of type SipServletRequest, while the doXXXResponse() methods take a single argument of type SipServletResponse. For example, a SIP invite request is dispatched to the doInvite() method, and a SIP response with a status code in the range between 200 and 300 is dispatched to the doSuccessResponse() method.

In the same way that web developers typically override the various doXXX() methods of HttpServlet, and do not modify the default implementation of its service() method (which contains the dispatch logic to the appropriate doXXX() method), SIP developers typically override only the doXXX() and doXXXResponse() methods of SipServlet.