The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Binod

Binod P.G is a senior staff engineer in the Java Web Services division at Sun Microsystems. He is an architect in the Application Server development team and is working on Project SailFin. He is also a co-specification lead of the Java EE Connector Architecture 1.6 Expert Group and a member of JDBC 4.0 expert group. In the past, he was involved in the development of many areas of the glassfish applicaton server, including Java EE Service Engine, Server Startup, Connector 1.5, JDBC, Connection Pool and JMS provider integration. He is also one of the owners of Generic Resource Adapter for JMS project. Prior to joining Sun in 2000, he has worked on a number of server side software technologies including IMS PL/1 programs in IBM Mainframes and internet projects in Microsoft IIS.

 

Binod's blog

SailFin CAFE: Adding communication capabilities to web applications made (very) simple.

Posted by binod on November 4, 2009 at 7:56 PM PST

So far I have described how create server applications that handle call, conference and IM using SailFin CAFE. In this edition lets take a look at how to add communication capabilities to web applications in a (very) simple way.

I like to start with the code. So, here is some code that implements making a phone call between two parties from the web application.

package my.test;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.glassfish.cafe.api.*;

public class CommunicatingServlet extends HttpServlet{

    @Context CommunicationSession session;

    @Override
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, java.io.IOException {

        java.io.PrintWriter out = response.getWriter();
        try {
            out.println("");
            String party1 = request.getParameter("party1");
            String party2 = request.getParameter("party2");
            Conversation conv  = session.createConversation(party1);
            conv.addParticipant(party2);
            out.println("Call started between " + party1 + " and " + party2);
        } finally {
            out.println("");
            out.close();
        }
    }

}

As you can see in the code above, an instance of CommunicationSession object is injected into the HTTP servlet. The session can then be used to create a conversation object specifying the parties in the call. All the further SIP protocol handling will be done by CAFE framework as per RFC 3725, unless the application wishes to modify any behavior (which I will explain another day).

CommunicationSession can be used to create any communication artifacts like conference, conversation, IMConversation etc as per the need of the application. It also share the session between communication bean and HTTP servlet. For example, for creating a conference between three people, the code would be something like the following.

            Conference conf  = session.createConference();
            conf.addParticipant(party1);
            conf.addParticipant(party2);
            conf.addParticipant(party3);

Similarly, for sending a message, the code would be.

            IMConversation conv  = session.createIMConversation(party1);
            conv.addParticipant(party2);
            conv.createTextMessage("Hi There").send();

To run the application, execute the following steps.

  • Download and install latest SailFin V2 promoted build.
  • Download and install latest SailFin CAFE build (b12 or later).
  • Package the application using the normal web application packaging format. Use your favorite IDE to do that. For compilation, please use SAILFIN_HOME/lib/communication-api.jar.
  • Start/Restart SailFin and deploy the application (eg: asadmin deploy firstcafewebapp.war).
  • Start two X-Lite phones.
  • Point your browser window/tab to
    http://localhost:8080/firstcafewebapp/CommunicatingServlet?party1=alice@example.com&party2=bob@example.com
    Or use curl
    curl -G -d "party1=alice@example.com&party2=bob@example.com" http://localhost:8080/firstcafewebapp/CommunicatingServlet
    Accept the phone calls as it reaches the X-Lite phones.
  • Watch this space for more information as I explain, (many) other features, spec compliance, etc.


    Related Topics >> Blogs      Glassfish      J2EE      Java Enterprise      Open Source      Servlets      Web Applications      
    Comments
    Comments are listed in date ascending order (oldest first)
    Syndicate content