Applications:Click2Dial - Code

From Wesip

From Wesip

This application implements a click2call 3pcc (third party call control) service that can be consumed using two kinds of interfaces. One is an ajax web page which uses DWR (Direct Web Remoting, http://getahead.ltd.uk/dwr) The second is a webservice implemented with Axis (AXIS, http://ws.apache.org/axis). Regardless of the access method chosen the SIP plane has been implemented following the variant 'Flow 1' of the RFC 3725 Best Current Practices for Third Party Call Control (3pcc) in the Session Initiation Protocol (SIP). See Applications:Click2Dial- Signalling.

After initiating the click2dial call both the ajax-dwr and webservice modes make subsequent requests to retrieve its status. In any case only one active call per HttpSession is permited.

The interface with the ajax webpage and the webservice is the the class C2C. It is used to trigger the call and to retrieve its status. C2CSession is a bean used to save all the data related to a particular click2call session including the status of endpoints.

The control of the SIP signalling relies on three SIP Servlets:

  • C2CSrcCallSipServlet : Takes care of the source(caller) call leg. Extends the C2CDefaultServlet.
  • C2CDstCallSipServlet : Takes care of the destination(callee) call leg. Extends the C2CDefaultServlet.
  • C2CDefaultServlet: Is the parent of C2CSrcCallSipServlet and C2CDstCallSipServlet servlets. As such carries out signalling tasks common to both call legs.

C2C

C2C has two functions

  • 1 Initiate calls
  • 2 Report status of initiated calls

Depending on the consumer (ajax-dwr or webservices) a different method is used to carry out those functions. The methods used by the webservice are c2cWS(String src, String dst, String password, String domain) to initiate calls and getStatus() to retrieve status of the active call, while the ones used by ajax-dwr are c2cDWR(String src, String dst, String password, String domain) to initiate calls and getC2CSession() to report status.

The method in charge of initiating SIP signalling is c2c(C2CSession c2cs) which encapsulates the UAC behaviour.

HttpSession httpSession = c2cs.getHttpSession();
ServletContext sc = httpSession.getServletContext();
//Get the SipFactory from the ServletContext
//we need it to initiate the call
SipFactory sipFactory = 
  (SipFactory) sc.getAttribute(SipServlet.SIP_FACTORY);
//Creating the INVITE request for the SRC user.
//Note that from and to are identical because
//the first call of the click2 to dial service
//is always for the originator
SipServletRequest inviteOrigin = 
  sipFactory.createRequest (
       sipFactory.createApplicationSession(),
       "INVITE",
       c2cs.getSrcAddress(),
       c2cs.getSrcAddress());
//Set a handler for responses and subsequent 
//requests of the source call leg
inviteOrigin.getSession().setHandler(C2C_SRC_SIP_SERVLET);
//Save the C2CSession in the application session
inviteOrigin.getApplicationSession().setAttribute(C2CSESSION, c2cs);
//Now we are ready to send the INVITE to the origin user
try {
   inviteOrigin.send();
} catch (Throwable e) {
....

This is the tipical UAC functionality which can be summarized as follows: Obtain the Servlet Context --> Obtain the SipFactory --> Create initial request --> Assign a handler servlet to the call --> Send the initial request

Note that the C2CSession bean that is going to save the status of this click2call session is stored in the ApplicationSession which conveniently will make her available to all SIP dialogs. At this point the initiation of the service is completed and the control is delegated to the servlets which will manage the SIP signalling.

In the meantime the methods that report status will be invoked repeatedly to report status of the click2call calls. Both methods refer to the httpSession to retrieve the C2CSession bean which holds the status of the service at any time. When using a webservice client make sure that it supports cookies, otherwise session can not be maintained and the webservice won't be able to show the status properly.


<< Signalling | Code II >>