Thursday Jun 17, 2010

SailFin-CAFE GreetingService Demo

SailFin-CAFE provides functionality to create conversation between User and MediaGroup. For instance, a simple snippet for playing an announcement to a user would look like:

   Player p = session.createParticipant(Player.class, "myPlayer");
   Conversation conv = session.createConversation(p);

CommunicationBeans can be used to listen media events, DTMF signals and many other events, based on which application logic can be decided.

Listener for media event when a player(announcement) is finished would be:

    @CommunicationEvent(type = CommunicationEvent.Type.MEDIAENDED)
    public void mediaEnded() {
        ----- application logic ------

DTMF Signal is intercepted through CommunicationEvent type MessageArrived:

    void handleMessage() {
        DtmfSignal ds = (DtmfSignal) ctx.getMessage();
        String signal = ds.getSignal();

At the same time Communication API makes it very handy to replace participants in a conversation. eg. Replacing a user with media group or vice-versa.

All this makes it quite simple to write applications like GreetingService. The basic idea of a GreetingService is to allow users to record messages to be played to their friends at a particular date and time.

Following image illustrates the above:

Greeting Service Example

In the above scenario Alice wants to wish Bob, so she logs in and schedules a greeting for Bob. GreetingService calls Alice for recording the message, CommunicationBean is used to play initial announcement and receive DTMF signals to start/stop recording the message. 

Once the recording is finished, an agent(GreetingAgent) is invoked to schedule the Greeting. GreetingAgent calls recepient at scheduled time and plays announcement informing about the Greeting.

Based on the DTMF response of the recepient, greeting is either played or rejected. Sender is informed about the status of the Greeting through an InstantMessage.

  • The sample can be checked out at :
  • Useful Links :

Thursday Apr 29, 2010

Call Forwarding in SailFin CAFE

SailFin CAFE makes call-forwarding apps much much simpler !!

1. The following describes, how all the incoming calls to Alice are forwarded to Bob:

public class CommsBean {

  @CommunicationEvent(type = CommunicationEvent.Type.INITIALIZATION)
  void handleInit() {
      Conversation call = (Conversation) ctx.getCommunication();
      if(call.getCallee().getName().equals("")) {


2. In case Alice takes up the call and then wants to forward it to a selected user, the code will look like:

public void handleMessageArrived(){     
    Conversation call=(Conversation)ctx.getCommunication();
    DtmfSignal ds=(DtmfSignal)ctx.getMessage();      
              UserParticipant part=(UserParticipant)call.getCallee();
                     call.addParticipant("") ;

Sample application can be downloaded from here.

Monday Jan 04, 2010

REST based hybrid(OSGI + JavaEE) - OSGI Framework Controller

GlassFish V3 comes with an OSGI Web Container, which provides the support for development of hybrid applications.

A hybrid application is a combination of Java EE and OSGI. More information about developing a simple hybrid application can be found here.

This blog entry describes about a REST based Web Application Bundle to control OSGI Framework.

Steps for the setup:

1. Download and install latest nightly build of glassfish-v3 from here.
2. Start the server using : asadmin start-domain
3. Download the OSGI Web Container bundle form here.
       Install it by copying the downloaded jar file to glassfishv3/glassfish/domains/domain1/autodeploy-bundles directory.
4. Get the ready to install REST based OSGI Framework controller OR

The complete netbeans project is available here. The project built with netbeans generates a plain war file, to make it an OSGI bundle, we need to update the MANIFEST.MF entry. Update the generated war by using the following command:
       jar -uvfm REST_WAB.war MANIFEST.MF

5. Install the application by copying it to glassfishv3/glassfish/domains/domain1/autodeploy-bundles directory. Server log will indicate the success of installation.
6. Use your browser to access the URL : http://localhost:8080/REST_WAB
       Click on View Bundles to get the status of modules in GlassFish v3. The framework controller allows for the install/uninstall, start/stop of the OSGI bundles.

rest framework controller
OSGI Framework Controller

Getting the OSGI Framework Bundle Context in a REST Application:

-- get the servlet context as:
        @Context ServletContext ctx;

-- getting the org.osgi.framework.BundleContext:
         BundleContext bundleContext = (BundleContext) ctx.getAttribute("osgi-bundlecontext");

The bundleContext can be used for running the OSGI Framework related commands.

Thursday Dec 03, 2009

Java EE Service Engine for GlassFish V3

GlassFish v3 provides the Sun Java EE Engine (Java EE Service Engine), a JSR 208-compliant Java Business Integration (JBI) runtime component that connects Java EE web services to JBI components. It acts as a bridge between the Java EE and JBI runtime environments for web service providers and web service consumers.

Here are the steps for using Java EE Service Engine with Fuji(OpenESB-v3)

- Download the latest GlassFish V3, promoted build from here. ( Download glassfish-v3-b\* or glassfish-v3-b\*-windows.exe file, so that the GlassFish update tool is also available.

- Install glassfish-v3, remember to check on "Install Updatetool" checkbox, during the installation. Let's call the GlassFish install directory as GF_HOME.

- Fuji-GlassFish container is available for installation with GlassFIsh-v3 at

- Installing the fuji-glassfish-container :
    cd $GF_HOME/glassfish
    jar -xvf ~fuji-gf-container.jar

- Start the glassfish update tool : $GF_HOME/bin/updatetool. Select Java EE Service Engine from the list of available addons and install it.


- Start domain :

     -- cd $GF_HOME/bin
     -- ./asadmin start-domain

- Deploying the Service Assembly:

     -- cp ~mySA.jar $GF_HOME/glassfish/domains/domain1/autodeploy/bundles or
     -- ./asadmin deploy ~mySA.jar

- Undeploying the Service Assembly:

     -- rm $GF_HOME/glassfish/domains/domain1/autodeploy/bundles/mySA.jar or
     -- ./asadmin undeploy mySA

Useful Links:

Java EE Service Engine Details:
List of available JBI components:

Wednesday Nov 25, 2009

SailFin CAFE - Maven Archetype

The CAFE Maven Archetype is now available for creating maven based projects for Sailfin CAFE. The project created will have a maven project metadata(pom.xml) and sample code for a basic click to call CAFE Application.

Steps to start developing SailFin-CAFE applications using Netbeans and Maven CAFE Archetype :

-- Create a new project : File --> New Project
-- Under maven category, select maven project.
-- Click on Add, to add the Maven CAFE Archetype to the list of available archetypes.
-- The following archetype details can be entered:
       \* GroupId :
       \* ArtifactId : cafe-archetype
       \* Version : 1.0-SNAPSHOT
       \* Repository :

cafe-archetype details

-- Now, select cafe-archetype and click next.
-- Enter the project details as shown in figure

cafe-archetype project details

-- Click Finish to create a Maven CAFE Application.
-- Right click on the project and Build it.
-- Your cafe application is ready to be deployed !!

Sunday Nov 22, 2009

Developing Sailfin CAFE Applications using Netbeans

Developing Sailfin CAFE Application with Netbeans is easier then ever. Resolve dependencies and build the project without any hassles.

Here's a quick guide to it:

- Create a new Netbeans project : File --> New Project
- In maven category, choose Maven Web Application, you will get the following window:

click finish to create a project.
- Right click on mavenproject1 - Source Packages and select new -> Java Class, to create a new Java Class.
- Make the class as CAFE CommunicationBean, by adding the following annotation:

public class NewClass {

- For resolving the missing dependency, select the tooltip next to @CommunicationBean annotation and click on Search Dependency at maven repositories.

searching maven dependency

- the following suggestion box will appear, select cafe-communication-api and select Add.

select cafe-communication-api

- Save the project, click on the tooltip next to @CommunicatioBean and select import

- Build the project and your CAFE Application is ready !!

- Steps to install and run the App:

  • Download and install latest SailFin V2 promoted build.
  • Download and install latest SailFin CAFE build.
  • Start SailFin and deploy the application. (eg: asadmin deploy mavenproject1.war)
  • Register two SIP phones with the help of steps mentioned here.
  • Click on Alice's phone and type "". Then click on green dial button. The bob's phone is ringing !!
  • Thursday Nov 05, 2009

    Sailfin CAFE - Click to Call using JSP

    Now your JSP is capable of establishing SIP calls. Thanks to Sailfin CAFE, no SIP Servlets needed !!!

    Here is the code you need to write:

        CommunicationSession commSession = (CommunicationSession) session.getAttribute("");
        String party1 = request.getParameter("party1");
        String party2 = request.getParameter("party2");
        try {
           Conversation conv = commSession.createConversation(party1);
           out.println("Call started between " + party1 + "and" + party2);
        } catch (Exception e) {

    Next, you would need to add a CAFE CommunicationBean to the Application.
    A simple CommunicationBean looks like:


    public class CafeCommsBean {

    Your Click to Call Application is ready !!

    Steps to install and run the App:

  • Download and install latest SailFin V2 promoted build.
  • Download and install latest SailFin CAFE build.
  • Package the application as a normal web application. For compilation, please use SAILFIN_HOME/lib/communication-api.jar.
  • Start/Restart SailFin and deploy the application (eg: asadmin deploy CafeApp.war).
  • Register two SIP phones by following the steps mentioned here.
  • Access http://localhost:8080/CafeApp
  • Enter the two user id's and click on call.
  • Click on the Answer button of the SIP Phones. The Call is established !!
  • Thursday Sep 03, 2009

    Integrating SailFin-CAFE with OpenIMS

    This entry demonstrates the procedure for installing OpenIMS and integrating Sailfin-CAFE with it. The attached sailfin-cafe application could then be used to establish a call between two clients registered with open-ims.


    • Install OpenIMS core.
    • Install Sailfin-CAFE, integrate it with OpenIMS.
    • Register IMS clients with OpenIMS core.
    • Deploy the cafe-app.
    • Establish call between the clients.

    Lets get started

    Installing OpenIMS core

    -- Install instructions can be found here.

    Note: If you are running the DNS on the same machine as OpenIMS core, then while configuring the DNS server, edit the file /etc/dhcp3/dhclient.conf and uncomment this line: prepend domain_name_servers;

    -- Start OpenIMS core components viz: pcscf, scscf, icsfc and FHoSS startup as given in the installation guide.

    Setting up SailFin and SailFin-CAFE

    -- Download and install SailFin from here.

    -- Use SailFin CAFE promoted build 05 or latest. The download and install instructions are available here.

    -- Register SailFin with OpenIMS core:

    • Go to http://localhost:8080 and enter hssAdmin as username & hss as password. This will lead you to FHoSS - FOKUS Home Subscriber Server webpage.
    • Click on create(Application Server) under the servcies tab.
    • The server setting parameters will be: Server Name - sip:hostname:5060, DiameterFDQN - hostname, Default Handling - Session-continued.
    • Attach the default_ifc to the newly created server.

    IMSClient setup

    -- UCT IMS Client can be dowloaded at

    -- OpenIMS Core has Alice and Bob as the users registered by default. Use two different IMS clients to login as Alice and Bob respectively.

    Deploying test application and establishing the call

    -- Download and deploy the sample application using sailfin asadmin deploy.

    -- Call Establishing logic of the test App:

        public class NewServlet extends HttpServlet {      
             @Context CommunicationSession session;

             protected void processRequest(HttpServletRequest request, HttpServletResponse response) {


                Call call  = session.createCall(party1);




    -- Access the url : http://localhost:8080/esswebv2

    -- Enter user ids : Alice@open-ims.test  and Bob@open-ims.test

    -- Click on the call button and listen the IMS Clients ringing !!


    The screencast for the complete setup can be viewed here !!

    Thursday Dec 25, 2008

    Event Notification Made Easy - GlassFish V3

    Tired of writing the complex event notifiers and the event listeners, you should no longer be.

    GlassFish v3, HK2 kernel has a clean and easy way to implement the event notification mechanism. Lets start with a simple Application Event Listener. This Listener will listen to any application deployed, changed or undeployed events.

    The object which we are listening should be marked as @Configured :-


    public interface SomeInterface ...{


    Now the Listener Should implement the ConfigListener Interface.

    The Listener for Application Events will look like:

    public class Listener implements ConfigListener {

    The object for which we are implementing the listener.
        private Applications allApplications; 

    The Following function provides the notifications of the Event.

    public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
        final UnprocessedChangeEvents unprocessed = ConfigSupport.sortAndDispatch(events, new Changed() {

        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> changedType, T changedInstance) {
                    switch (type) {
                        case ADD: //
    changedInstance was added to the parent
                        case CHANGE: //
    changedInstance has mutated
                        case REMOVE: //
    changedInstance was removed from the parent

    Whenever some Application Event Occurs all the implementors of ConfigListener which are injecting the Applications interface are notified.

    Hello World - GlassFish-V3 Module

    GlassFish v3 has a modular and extensible architecture. Hence, it provides a lot of opportunities to add more and more functionality to it. So, why not explore its modular architecture with a simple hello world module !!!
    To start with we need to be familiar with the HK2 component services and OSGi module management subsystem.
    In our example we will extend the asadmin command to add our own hello command to the admin command utility.

    Method Decleration:

    AdminCommand is exposed by glassfish through annotation @contract, this has to be implemented in order to make use of the asadmin command. Hello command will be implemented as a service using the annotation @Service, which helps in the runtime discovery of the command.The command name is specified with the @Service annotation.

    public class HelloCommand implements AdminCommand{

    Command Execution:
    To enable an asadmin command to run, we need to implement the execute method of the AdminCommand interface. The execute method is declared as:

    public void execute(AdminCommandContext context){
    The ActionReport which is obtained from AdminCommandContext is used to return the command status or error message to the client, hence the complete hello world execute method will be:

    public void execute(AdminCommandContext context){
            ActionReport report = context.getActionReport();
            report.setMessage("Hello World !!!");

    Writing pom.xml for the project:

    Our project structure is:
            |---> pom.xml
            |---> hello-command

    The pom.xml under hello.command is the top level pom.xml with the packaging type pom. Which will be more useful is case there are multiple modules.

    pom.xml under hello-command includes:

    Identification of the module.
          <name>Hello Command Sample</name>

    Required Plugins, maven-bundle-plugin and hk2-maven-plugin, are specified as:

    The Dependencies are mentioned as follows:

    Playing with the example:

    1. The complete example can be downloaded here.
    2. Unzip the module in your favourite directory.
    3. cd hello.command
    4. mvn clean install
    5. copy hello-command/target/hello-command-1.0-SNAPSHOT.jar to Glassfish-v3-installation-dir/modules
    6. Start the server.
    7. Execute the command : asadmin hello
    8. Output: Hello World !!!

    I hope it will be useful for the beginners like me.
    Cheers !!!


    Mohit Gupta


    « July 2016