Skip to main content

Writing Your First SailFin CAFE Application.

Posted by binod on October 1, 2009 at 3:11 AM PDT

How do you write a application that enables communication between two SIP phones? What if you also want to
support video calling?

If you are using SIP servlets, you would be writing one or two sip servlets (atleast a few hundred lines of SIP servlet code)
to achieve this. But if you are using Sailfin CAFE, then things change quite dramatically. Here is the code to do
all of the above, I mentioned.

package my.test;
@org.glassfish.cafe.api.bean.CommunicationBean
public class YourCommunicationPOJO {
}

Thats it!

Under the hood, Framework handles all common activities like registration, SIP invite handling etc using a B2bUA application.
Ofcourse, application can override the default behavior using CAFE apis. There is lot more you
can do with SailFin CAFE, which I will explain in the subsequent blogs as the project progress further.

Lets take a look at running this application. Here are the steps.

  • Download and Install SailFin V2 b31c
  • Download and install latest SailFin CAFE build.
  • 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 SailFin and deploy the application (eg: asadmin deploy firstcafe.war)
  • Now your application is ready to test against any SIP phones. Here is some more information on how to test this application
    using X-Lite.

  • Setup two X-Lite phones with accounts "alice@example.com" and "bob@example.com" respectively. They will register with SailFin CAFE
  • Click on Alice's phone and type "bob@example.com". Then click on green dial button. See the picture below
  • You can start the video in X-Lite phone to send the video to the other person.


  • Comments

    hi Binod, first of all thank you for posting sainlfin ...

    hi Binod,

    first of all thank you for posting sainlfin cafe tutorials that should help me a lot on my graduation project.

    i am working on an application that enables VOIP between sip phones or pcs and i am really confused.i have created a web project on eclipse and i dont know where i should put the code above (in new class maybe), please if you could give some more details for the packaging and the compilation part that would be great. thank you.

    can't make call

    I installed sailfin and sailfin cafe and use eclipse. Then created web project everything is okey except calling. I can register but cant call other registered user. (ubuntu 9.04, softphone twinkle)

    Re: can't make call

    Can you please enable sailfin-cafe logging and send me the log file (binod@dev.java.net)

    here is my error appears at twinkle

    Line 1: call failed. 302 Moved Temporarily The call can be redirected to: sip:192.168.2.2:5060

    twinkle 302 moved temporarly

    I found something in this site about this event. But cant understand anything. http://osdir.com/ml/voip.twinkle/2008-01/msg00049.html

    after enable sailfin cafe this log file I get

    [#|2010-04-14T00:09:10.555+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=15;_ThreadName=SipContainer-serversWorkerThread-5060-9;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=3db76593-53a9-4528-8149-9754c7dc0aa5;|Received Message : REGISTER sip:192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 0 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: ;expires=0 To: "Bob" Cseq: 367 REGISTER User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKkvwjixus;received=192.168.2.2 Call-Id: pztrqxsacqyhdkv@ubuntu.ubuntu-domain From: "Bob";tag=cwuxw |#] [#|2010-04-14T00:09:12.126+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=16;_ThreadName=SipContainer-serversWorkerThread-5060-0;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=4565a34f-c2c1-447e-b53c-d57f9ccad985;|Received Message : REGISTER sip:192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 0 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: ;q=0.920;expires=3600 To: "Bob" Cseq: 368 REGISTER User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKnedbcydr;received=192.168.2.2 Call-Id: pztrqxsacqyhdkv@ubuntu.ubuntu-domain From: "Bob";tag=ouogj |#] [#|2010-04-14T00:10:25.081+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=17;_ThreadName=SipContainer-serversWorkerThread-5060-6;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=23d7f4c1-a846-4272-94ec-5f5d8357e62f;|Received Message : REGISTER sip:192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 0 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: ;expires=0 To: "Bob" Cseq: 369 REGISTER User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKclqzjcwf;received=192.168.2.2 Call-Id: pztrqxsacqyhdkv@ubuntu.ubuntu-domain From: "Bob";tag=epzou |#] [#|2010-04-14T00:10:26.361+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=18;_ThreadName=SipContainer-serversWorkerThread-5060-4;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=e3ba4c45-f2a2-4765-bbf5-8ff22da8a345;|Received Message : REGISTER sip:192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 0 Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: ;q=0.920;expires=3600 To: "Bob" Cseq: 370 REGISTER User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKtbnbkdfn;received=192.168.2.2 Call-Id: pztrqxsacqyhdkv@ubuntu.ubuntu-domain From: "Bob";tag=lefhz |#] [#|2010-04-14T00:12:48.751+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=19;_ThreadName=SipContainer-serversWorkerThread-5060-1;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=53ab34db-50f1-47fe-a95e-0e3b488d9731;|Received Message : INVITE sip:fatih@192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 314 Supported: replaces, norefersub, 100rel Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: To: Cseq: 434 INVITE User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKjmwlyzso;received=192.168.2.2 Content-Type: application/sdp Call-Id: njbtaciuevmfeob@ubuntu.ubuntu-domain From: "Bob";tag=lbiqi v=0 o=twinkle 2024948881 127941040 IN IP4 192.168.2.2 s=- c=IN IP4 192.168.2.2 t=0 0 m=audio 8000 RTP/AVP 98 97 8 0 3 101 a=rtpmap:98 speex/16000 a=rtpmap:97 speex/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:3 GSM/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 a=zrtp |#] [#|2010-04-14T00:12:48.901+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=19;_ThreadName=SipContainer-serversWorkerThread-5060-1;ClassName=org.glassfish.cafe.core.CafeBeanContainer;MethodName=send;_RequestID=53ab34db-50f1-47fe-a95e-0e3b488d9731;|Sent message INVITE sip:fatih@192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 314 Contact: To: Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Supported: replaces, norefersub, 100rel Cseq: 1 INVITE User-Agent: Twinkle/1.2 Content-Type: application/sdp From: "Bob";tag=g7z7lamc-5 Call-Id: 192.168.2.2_1_4366248468156495959 v=0 o=twinkle 2024948881 127941040 IN IP4 192.168.2.2 s=- c=IN IP4 192.168.2.2 t=0 0 m=audio 8000 RTP/AVP 98 97 8 0 3 101 a=rtpmap:98 speex/16000 a=rtpmap:97 speex/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:3 GSM/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 a=zrtp |#] [#|2010-04-14T00:12:48.910+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=15;_ThreadName=SipContainer-serversWorkerThread-5060-9;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doResponse;_RequestID=3db76593-53a9-4528-8149-9754c7dc0aa5;|Received Message : SIP/2.0 302 Moved Temporarily To: ;tag=g7z7lamk-6 Contact: Cseq: 1 INVITE Call-Id: 192.168.2.2_1_4366248468156495959 From: "Bob";tag=g7z7lamc-5 Server: Glassfish_SIP_2.0.0 |#] [#|2010-04-14T00:12:48.911+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=15;_ThreadName=SipContainer-serversWorkerThread-5060-9;ClassName=org.glassfish.cafe.core.CafeBeanContainer;MethodName=send;_RequestID=3db76593-53a9-4528-8149-9754c7dc0aa5;|Sent message SIP/2.0 302 Moved Temporarily To: Cseq: 434 INVITE Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKjmwlyzso;received=192.168.2.2 Server: Glassfish_SIP_2.0.0 From: "Bob";tag=lbiqi Call-Id: njbtaciuevmfeob@ubuntu.ubuntu-domain |#] [#|2010-04-14T00:14:01.733+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=20;_ThreadName=SipContainer-serversWorkerThread-5060-7;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doRequest;_RequestID=58b751ce-7a07-4f5e-bf8b-ab825571e663;|Received Message : INVITE sip:fatih@192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 315 Supported: replaces, norefersub, 100rel Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Contact: To: Cseq: 549 INVITE User-Agent: Twinkle/1.2 Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKromenmxb;received=192.168.2.2 Content-Type: application/sdp Call-Id: bqdvrhfnoaateqx@ubuntu.ubuntu-domain From: "Bob";tag=rshic v=0 o=twinkle 2062467758 2054004971 IN IP4 192.168.2.2 s=- c=IN IP4 192.168.2.2 t=0 0 m=audio 8000 RTP/AVP 98 97 8 0 3 101 a=rtpmap:98 speex/16000 a=rtpmap:97 speex/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:3 GSM/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 a=zrtp |#] [#|2010-04-14T00:14:01.737+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=20;_ThreadName=SipContainer-serversWorkerThread-5060-7;ClassName=org.glassfish.cafe.core.CafeBeanContainer;MethodName=send;_RequestID=58b751ce-7a07-4f5e-bf8b-ab825571e663;|Sent message INVITE sip:fatih@192.168.2.2 SIP/2.0 Max-Forwards: 70 Content-Length: 315 Contact: To: Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, REFER, NOTIFY, SUBSCRIBE, INFO, MESSAGE Supported: replaces, norefersub, 100rel Cseq: 1 INVITE User-Agent: Twinkle/1.2 Content-Type: application/sdp From: "Bob";tag=g7z7mutj-8 Call-Id: 192.168.2.2_2_538547753248985153 v=0 o=twinkle 2062467758 2054004971 IN IP4 192.168.2.2 s=- c=IN IP4 192.168.2.2 t=0 0 m=audio 8000 RTP/AVP 98 97 8 0 3 101 a=rtpmap:98 speex/16000 a=rtpmap:97 speex/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:3 GSM/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 a=zrtp |#] [#|2010-04-14T00:14:01.753+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=21;_ThreadName=SipContainer-serversWorkerThread-5060-5;ClassName=org.glassfish.cafe.core.Servlet;MethodName=doResponse;_RequestID=eee95ee6-f16c-441f-8722-699f59fbd2b9;|Received Message : SIP/2.0 302 Moved Temporarily To: ;tag=g7z7muty-9 Contact: Cseq: 1 INVITE Call-Id: 192.168.2.2_2_538547753248985153 From: "Bob";tag=g7z7mutj-8 Server: Glassfish_SIP_2.0.0 |#] [#|2010-04-14T00:14:01.755+0300|FINE|sun-glassfish-comms-server2.0|sailfin-cafe|_ThreadID=21;_ThreadName=SipContainer-serversWorkerThread-5060-5;ClassName=org.glassfish.cafe.core.CafeBeanContainer;MethodName=send;_RequestID=eee95ee6-f16c-441f-8722-699f59fbd2b9;|Sent message SIP/2.0 302 Moved Temporarily To: Cseq: 549 INVITE Via: SIP/2.0/UDP 192.168.2.2:5062;rport=5062;branch=z9hG4bKromenmxb;received=192.168.2.2 Server: Glassfish_SIP_2.0.0 From: "Bob";tag=rshic Call-Id: bqdvrhfnoaateqx@ubuntu.ubuntu-domain |#]

    Re: after enable sailfin cafe this log file I get

     Thanks for the log file you sent me. Will reply you on e-mail. 

    Enabling CAFE logging.

    Enabling CAFE logging.
    http://twitter.com/binodpg/status/12116075894