Tutorial:Converged HTTP & SIP Applications

From Wesip

From Wesip

Converged applications are compound of SIP and HTTP servlets. They are executed in an single converged context therefore they can share resources and save and retrieve attributes in a common store.

HTTP servlets and jsp pages, just like SIP servlets, can initiate SIP dialogs acting in a UAC fashion. To do so the HttpServlet or jsp retrieves the SipFactory from the context and follows the standard UAC techniques providing the name of the SipServlet that is supposed to handle responses and subsequent requests of the new created dialog.

Think of a click-to-dial application. A SIP dialog is initiated by the HTTP part of the application which is part of a 3pcc (3rd party control call, RFC 3725). This dialog is the connection with the caller. As the 3pcc takes place another dialog (the connection with the callee) is established under the same application session. The HTTP part of the application (the web page) reports the status of the callee and caller at all times.

The UAC code in the jsp would look like this.

....

//Retrieve SipFactory through the context
ServletContext sc = request.getSession().getServletContext();
SipFactory sf = (SipFactory) sc.getAttribute("javax.servlet.sip.SipFactory");

//Create a new application session (required for request creation)
SipApplicationSession applicationSession = sf.createApplicationSession(); 

//Create the new request using the SipFactory
//and the SipApplicationSession
SipServletRequest sipRequest = 
                    sf.createRequest(sas, "INVITE", callerURI, calleeURI);  

//Retrieve the SipSession that represents
//the new dialog
SipSession sipSession = sipRequest.getSession();
//Assign the preferred SipServlet as handler 
//of subsequent responses and requests
sipSession.setHandler("theHandlerSipServlet"); 

//Save a reference in the HttpSession to the 
//SipApplication session that we just created
request.getSession().setAttribute("theApplicationSession",applicationSession);
//Send the request
req.send();

....

The resulting SIP messages will be processed by the SIP servlet called theHandlerSipServlet which will connect caller and calle as per the 3pcc standar and report of the status of the two endpoints to the HttpServlet.

....
protected void doResponse(SipServletResponse resp)
                  throws javax.servlet.ServletException,
                         java.io.IOException{
     
     ....
      
     //Save the status of the endpoint in the application session
     //using the endpoint display name as key
     Integer responseStatus = new Integer(resp.getStatus());
     
     SipApplicationSession sas = resp.getSession().getApplicationSession();
     sas.setAttribute(resp.getDisplayName(),responseStatus);
      
     ....
}
 
....

Now, the jsp page can report the status of the caller and callee retrieving the data from the application session

....
//Retrieve application session. It was saved
SipApplicationSession appSession = 
           (SipApplicationSession)request.getSession().getAttribute("theApplicationSession");

//Report the status of every connection
Iterator endpoints = appSession.getAttributeNames();

while (endpoints.hasNext()) {
      String displayName =  (String)endpoints.next();
      Integer status = (Integer)appSession.getAttribute(displayName);
      
      //report the status 
      myReportMethod(displayName,status);
      
}
....

<< Working as Proxy II | Accessing the SIP message content >>