binod's bloghttp://www.java.net/blogs/binod
enWhat is new SIP Servlet 2.0 : Part Ihttp://www.java.net/blog/binod/archive/2013/05/06/what-new-sip-servlet-20-part-i
<!-- | 0 --><p>There are a number of topics <a href="http://www.jcp.org/en/jsr/detail?id=359">JSR 359</a> EG is working on. These are on a number of different categories. It includes improving the RFC coverage of SIP specification (SIP outbound), Modernizing programming (using POJOs), better alignment with Java EE (CDI, latest servlet spec), SIP over websockets, Extensibility, Better concurrency control, Updates to B2B etc. In this blog series, I am<br />
planning to give an update on these features and others that we are working on in the expert group.</p>
<p>Lets start with SIP POJOs.</p>
<p>Expert group in our f2f in January felt that, time is probably right to provide a simplified and more modern way to write SIP servlet applications. Also, SIP has much more methods and types of messages than a typical http servlet application handles (GET, POST etc). So, the need for a simpler programming model with a lesser dependency on <code class="prettyprint">GenericServlet</code> is more obvious for a SIP servlets.</p>
<p>So, with SIP Servlet 2.0, a POJO can be annotated with an @SipServlet annotation and the java methods in such a SIP POJO will be able to able act as SIP message handler. Following is an example of<br />
such a SIP POJO.</p>
<pre class="prettyprint"><code>@SipServlet<br />public class FooPOJO {<br /> @Invite<br /> public void handleInviteRequest(SipServletRequest request) {<br /> //...<br /> }<br /> @Invite<br /> public void handleInviteResponse(SipServletResponse response) {<br /> //...<br /> }<br /> @ProvisionalResponse<br /> public void handleSuccessResponse(SipServletResponse response) {<br /> //...<br /> }<br />}</code></pre>
<p>Each of the SIP method annotations use one or more defined SIP meta annotations, which make the story more extensible. Take a look at the definition of @Invite and @SuccessResponse below.</p>
<pre class="prettyprint"><code>@Retention(RUNTIME)<br />@Target({METHOD})<br />@SipMethod("INVITE")<br />public @interface Invite {<br />}</code></pre>
<p>As you can see, the <code class="prettyprint">@SipMethod</code> meta annotation drive the logic. </p>
<pre class="prettyprint"><code>@Retention(RUNTIME)<br />@Target({METHOD})<br />@SipResponseRange(begin = 100, end = 199)<br />public @interface ProvisionalResponse {<br />}</code></pre>
<p>and here @SipResponseRange meta annotation decide the logic. There are couple more meta annotations defined in the specification. It is possible for application to define their own annotations by using one or more of these meta annotations. The container is expected to behave based on the meta annotations, that appear on annotations put in a method, rather than the annotations itself.</p>
<pre class="prettyprint"><code>@Retention(RUNTIME)<br />@Target({METHOD})<br />@SipResponseRange(begin = 200, end = 299)<br />@SipMethod("INVITE")<br />public @interface MySucessfulInviteResponse {<br />}</code></pre>
<p>As you can see above, an application has used <code class="prettyprint">@SipMethod</code> and <code class="prettyprint">@SipResponseRange</code> for a custom annotation. </p>
<pre class="prettyprint"><code>@Retention(RUNTIME)<br />@Target({METHOD})<br />@SipPredicate(InitialInvite.Predicate.class)<br />@SipMethod("INVITE")<br />public @interface MyInitialInvite {<br /> class Predicate implements javax.servlet.sip.Predicate<SipServletRequest> {<br /> @Override<br /> public boolean apply(final SipServletRequest request) {<br /> return request.isInitial();<br /> }<br /> }<br />}</code></pre>
<p>And in the above example, application has used a more powerful <code class="prettyprint">@SipPredicate</code> to specify a custom filtering logic. Such custom annotations can now be used to annotate a SIP handler method.</p>
<p>More information (eg: method selection criteria) on this and also about all other features are available in the <a href="http://jcp.org/aboutJava/communityprocess/edr/jsr359/index.html">early draft</a>. Join the <a href="http://java.net/projects/sipservlet-spec/">sipservlet-spec java.net project</a> to participate in the process. </p>
http://www.java.net/blog/binod/archive/2013/05/06/what-new-sip-servlet-20-part-i#commentsBlogsJava CommunicationsJava EnterpriseJCPMon, 06 May 2013 09:50:32 +0000binod895955 at http://www.java.netJSR 359: SIP Servlet 2.0http://www.java.net/blog/binod/archive/2012/09/03/jsr-359-sip-servlet-20
<!-- | 0 --><p><a href="http://jcp.org/en/jsr/detail?id=359">JSR 359</a> has been accepted by Java SE/EE executive committee a month back. Please see the<a href="http://jcp.org/en/jsr/detail?id=359#2"> specification request</a> for the content of this revision of SIP Servlet 2.0 specification. We have established a <a href="http://java.net/projects/sipservlet-spec">java.net project</a> for cordinating and communicating the progress of the specification. The work is about to get started. At the moment, the expert group is being formed and some of the leading sipcontainer/telco vendors have already joined the group. Here is a short how to wiki on "<a href="http://java.net/projects/sipservlet-spec/pages/JoiningJSR359EG">joining the expert group</a>". </p>
<p>I will be using this blog for posting the progress on the JSR. So, please watch this space!</p>
http://www.java.net/blog/binod/archive/2012/09/03/jsr-359-sip-servlet-20#commentsBlogsJ2EEJava CommunicationsJava EnterpriseJCPProgrammingServletsTue, 04 Sep 2012 05:50:03 +0000binod889813 at http://www.java.netSailFin CAFE: Preview Release now available.http://www.java.net/blog/binod/archive/2010/09/21/sailfin-cafe-preview-release-now-available
<!-- | 6 --><div>
<p>A preview release of <a href="https://sailfin-cafe.dev.java.net/">SailFin CAFE</a> is now <a href="https://sailfin-cafe.dev.java.net/download.html">available</a>. We announced this project <a href="http://forums.java.net/jive/thread.jspa?threadID=62270">during last JavaOne</a> and then onwards a lot of progress has been made. A number of people from Sun/Oracle and Ericsson contributed code to the project. And many in the community have tried it and gave feedback. Thanks a lot for all contributions. I also want to note that the framework is known to work with multiple sip servlet containers now.</p>
</div>
<div>
<p>If you are at JavaOne/Oracle Open World today, <a href="http://www.eventreg.com/cc250/sessionDetail.jsp?SID=313768">attend CAFE BOF at 7pm tonight</a> at Hilton to get detailed information on the framework.&nbsp;</p>
<p>Here is a list of key features. <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/index.html">Take a look at the javadoc</a> for all the java apis.&nbsp;</p>
<ul>
<li>Conversation&nbsp;</li>
<li>Conference&nbsp;</li>
<li>DTMF</li>
<li>Instant Messaging (simple text messaging, typing detection)</li>
<li>MSRP (File Transfer, Messaging)</li>
<li>User Procedures (Registration and Presence)</li>
<li>Presence Simulator</li>
<li>Media (Playing, Recording etc)</li>
<li>Security Annotations</li>
<li>Initial REST support</li>
<li>Extensibility</li>
</ul>
</div>
<div>
<p>A number of blogs are written by developers that give a good idea on the framework. Here is a list of some important ones. The front page of the <a href="https://sailfin-cafe.dev.java.net/">sailfin cafe website</a> has an exhaustive list of the blogs.</p>
<ul>
<li><a href="http://weblogs.java.net/blog/binod/archive/2009/10/01/writing-your-first-sailfin-cafe-application">Writing your First SailFin CAFE application</a></li>
<li>SailFin CAFE Fundamentais <a href="http://java.dzone.com/articles/sailfin-cafe-fundamentals">Part I</a>, <a href="http://weblogs.java.net/blog/binod/archive/2010/05/14/sailfin-cafe-using-presence-and-conversation-together">Part II</a></li>
<li><a href="http://blogs.sun.com/mohitg/entry/call_forwarding_in_sailfin_cafe">Call Forwarding, Redirecting</a></li>
<li><a href="http://weblogs.java.net/blog/erikvandervelden/archive/2010/04/12/cafe-using-presence-cafe">Using Presence</a></li>
<li><a href="http://weblogs.java.net/blog/bhavanishankar/archive/2010/04/05/addition-msrp-protocol-support-sailfin-cafe">MSRP support</a>&nbsp;</li>
<li><a href="http://www.java.net/blog/rampsarathy/archive/2010/01/25/resting-sailfin-cafe">REST introduction</a></li>
<li><a href="http://www.java.net/blog/bhavanishankar/archive/2010/02/26/running-cafe-applications-occas-preliminary-notes">Running SailFin CAFE on OCCAS</a></li>
</ul>
<p>A number of samples are available. You can check them out from svn repository. (svn co --username guest <a href="https://sailfin-cafe.dev.java.net/svn/sailfin-cafe/trunk/cafe-samples" title="https://sailfin-cafe.dev.java.net/svn/sailfin-cafe/trunk/cafe-samples">https://sailfin-cafe.dev.java.net/svn/sailfin-cafe/trunk/cafe-samples</a>). Following are some applications available for trying out.&nbsp;</p>
<ul>
<li>Getting Started (two party call, conference)</li>
<li>Music Store</li>
<li>Conference Application (with DTMF, Announcements etc)</li>
<li>Greeting service</li>
<li>Call-When-Online (Presence + Call)</li>
<li>Hunt Group</li>
</ul>
</div>
<p>&nbsp;Download and use it, and send any feedback to <a href="mailto:users@sailfin.dev.java.net">users@sailfin.dev.java.net</a>.</p>
http://www.java.net/blog/binod/archive/2010/09/21/sailfin-cafe-preview-release-now-available#commentsBlogsTue, 21 Sep 2010 07:56:31 +0000binod484977 at http://www.java.netSailFin CAFE: Upcoming Presentations.http://www.java.net/blog/binod/archive/2010/08/01/sailfin-cafe-upcoming-presentations
<!-- | 0 --><p>Here is a list of SailFin CAFE presentations that we will be presenting in next 2-3 months.</p>
<p style="font-family: lucida, arial, sans-serif; font-size: 12px; ">This week there are couple of presentations. The first one is at Munich JUG at 7pm, monday 2nd August.&nbsp;<a style="text-decoration: none; color: rgb(0, 102, 153); " href="http://www.jugm.de/">More details are here</a>.&nbsp;The next one is an Industry Talk on tuesday (between 9am and 10.30am) at IPTComm, Munich, Germany.&nbsp;<a style="text-decoration: none; color: rgb(0, 102, 153); " href="http://iptcomm.org/program/index.html">Visit IPTComm website</a>&nbsp;for more details.</p>
<p style="font-family: lucida, arial, sans-serif; font-size: 12px; ">In september, there is BOF session at&nbsp;<a style="text-decoration: none; color: rgb(0, 102, 153); " href="http://www.oracle.com/us/javaonedevelop/index.html">JavaOne</a>. This will be at Tuesday 21 September 7pm at Hilton San Francisco.&nbsp;</p>
<p style="font-family: lucida, arial, sans-serif; font-size: 12px; ">The next one is a Conference Session at&nbsp;<a style="text-decoration: none; color: rgb(0, 102, 153); " href="http://itexpo.com">TMCNet ITExpo</a>, Los Angeles Convention Centre at 11.30am October 5.</p>
<p style="font-family: lucida, arial, sans-serif; font-size: 12px; ">Please join us for the presentation, if you are around locally or if you are attending these conferences.</p>
<p>&nbsp;</p>
http://www.java.net/blog/binod/archive/2010/08/01/sailfin-cafe-upcoming-presentations#commentsBlogsSun, 01 Aug 2010 20:24:03 +0000binod457544 at http://www.java.netSailFin CAFE Fundamentals Part II: Communications and UserProcedures (with an example)http://www.java.net/blog/binod/archive/2010/05/17/sailfin-cafe-fundamentals-part-ii-communications-and-userprocedures-ex
<!-- 1173 | 6 --><img src="/images/people/binod.jpg" border="0", align="left" /><div>
<p>Here is the second part of the CAFE fundamentals blog series. This time, I am explaining two important interfaces called <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Communication.html">Communication</a> and <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/UserProcedure.html">UserProcedure</a> with an example. If this is the first time you are hearing about <a href="https://sailfin-cafe.dev.java.net/">SailFin CAFE,</a> I recommend reading the <a href="http://java.dzone.com/articles/sailfin-cafe-fundamentals">CAFE fundamentals article</a> and the blog on <a href="http://weblogs.java.net/blog/binod/archive/2009/10/01/writing-your-first-sailfin-cafe-application">writing your first CAFE application</a>. The core of this discussion is an example which shows triggering a Conversation when the callee comes online. Just like the earlier examples in my previous blogs, this one also doesn't have any SIP Servlets and is written using the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/index.html">higher level API </a>provided by SailFin CAFE.</p>
</div>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/communication.png" /></p>
<div>At first, lets take a look at Communication interface in CAFE. Just as the name implies it is any form of <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Communication.html">Communication</a> between 2 or more <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Participant.html">Participants</a>. It can be text/audio/video/filetransfer etc. There are 6 kinds of Communication interfaces exposed by CAFE at the moment.</div>
<ol>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Conversation.html">Conversation</a> : Communication between two Participants. Typically this is between two user agents (or sip phones). It can also be between a sip phone and a <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Player.html">Player</a>/<a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Recorder.html">Recorder</a>.&nbsp;</li>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Conference.html">Conference</a>: As the name implies it is a communication between more than two user agents, which mandates the use of a media mixer in the media server always.&nbsp;</li>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/IMConversation.html">IMConversation</a>: This is a text chat between two user agents.&nbsp;</li>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/IMConference.html">IMConference</a>: A text chat between more than two participants, which is brokered by the server.</li>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/MSRPConversation.html">MSRPConversation</a>. A two-party communication that uses <a href="http://en.wikipedia.org/wiki/Message_Session_Relay_Protocol">MSRP</a> protocols, mainly to transfer files and sending messages.&nbsp;</li>
<li><a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/MSRPConference.html">MSRPConference</a>: A multi-party communication that uses MSRP protocol internally. This is always brokered by an MSRP relay server in CAFE.</li>
</ol>
<div>A Communication can be created as a result of arrival of a SIP Message from a user agent or it can be created explicitly by the application (eg: web application). If the Communication is created as a result of an incoming SIP request, CAFE will always treat it as a two party communication. Application can then use the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/CommunicationEvent.Type.html#INITIALIZATION">INITIALIZATION</a> event in the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/CommunicationBean.html">CommunicationBean</a> to convert such a two party communication to a multi-party communication. Take a look at <a href="http://weblogs.java.net/blog/binod/archive/2009/10/18/sailfin-cafe-implementing-simple-conference-application">this blog for an example</a>.</div>
<div>&nbsp;</div>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/userprocedure.png" /></p>
<div>On the other hand, any interaction or a procedure between a user agent and the server is represented as the interface <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/UserProcedure.html">UserProcedure</a>. <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Registration.html">Registration</a>, <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/PresenceSource.html">PresenceSource</a>, <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/PresenceWatcher.html">PresenceWatcher</a> and <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/WatcherInfoSubscriber.html">WatcherInfoSubscriber</a> are the types of UserProcedures. Each UserProcedure has a certain life span associated with it, after which it will expire. Application can refresh the UserProcedure to extend its life. For example, a Registration created by the application would timeout after a period of time. Application can refresh the registration during the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/UserProcedureEvent.Type.html#ABOUTTOEXPIRE">ABOUTTOEXPIRE</a> event. <a href="http://www.java.net/blog/332280">Erik has explained</a> UserProcedures in his blogs <a href="http://www.java.net/blog/erikvandervelden/archive/2010/01/21/cafe-userprocedures-integrated-trunk-0">here</a> and <a href="http://www.java.net/blog/erikvandervelden/archive/2010/04/12/cafe-using-presence-cafe">here</a>.</div>
<div>&nbsp;</div>
<div>Now, lets take a look at a real example. In this example, a <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Conversation.html">Conversation</a> is initiated either by sip user agent or a web application. However lets imagine that the callee's phone is not online yet. In this service, application creates a <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/PresenceWatcher.html">PresenceWatcher</a> to watch the Presence status of the callee for for a stipulated period of time. If the callee bring up his phone by that time, the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/CommunicationBean.html">CommunicationBean</a> is notified with a <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/UserProcedureEvent.Type.html#NOTIFICATION">NOTIFICATION</a> pertaining to the PresenceWatcher and the call is then initiated.</p>
<div>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/callbean.png" /></p>
<div>The example application contains two CommunicationBeans. First one, CallBean is of the type Conversation for handling events related to Conversation and another (PresenceBean) with type PresenceWatcher to handle the presence notifications.</div>
<div>&nbsp;</div>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/presencebean.png" /></p>
</div>
<div>As you can see in the code, when the Conversation is rejected by the callee, the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/ParticipantEvent.Type.html#REJECTED">ParticipantEvent.Type.REJECTED</a> will be invoked. There the application, creates a PresenceWatcher with an expiration time of 5 minutes. So, if the callee switch on his phone in next five minutes, the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/UserProcedureEvent.Type.html#NOTIFICATION">UserProcedureEvent.Type.NOTIFICATION</a> is triggered in the PresenceBean. And the application in the event creates a Conversation to establish the call again between the parties.</div>
<div>&nbsp;</div>
<div>Full source code of the application is checked into the <a href="https://sailfin-cafe.dev.java.net/source/browse/sailfin-cafe/trunk/cafe-samples/callwhenonline/">SailFin CAFE SVN&nbsp;repository</a>. Here are the steps to run the sample</div>
<ol>
<li>Install SailFin and SailFin CAFE <a href="http://weblogs.java.net/blog/binod/archive/2009/10/01/writing-your-first-sailfin-cafe-application">as mentioned in this blog</a>.</li>
<li>Checkout the sample and build using maven 2.&nbsp;</li>
<li>Start the SIP client of one user (eg: Alice) and Make a call to Bob. [<a href="http://weblogs.java.net/blog/binod/archive/2009/09/29/tips-working-x-lite">For X-Lite tips, see this blog</a>]</li>
<li>Since Bob's phone is not active, after a while, the call will be rejected by the server.</li>
<li>Now start Bob's phone. The moment it starts, a call will be established between the Alice and Bob.&nbsp;</li>
</ol>
</div>
<p>&nbsp;Play with <a href="https://sailfin-cafe.dev.java.net/">SailFin CAFE</a> and let us know your feedback at <a href="mailto:users@sailfin.dev.java.net">users@sailfin.dev.java.net</a>.</p>
http://www.java.net/blog/binod/archive/2010/05/17/sailfin-cafe-fundamentals-part-ii-communications-and-userprocedures-ex#commentsBlogsJava EnterpriseOpen SourceMon, 17 May 2010 09:26:55 +0000binod412458 at http://www.java.netSailFin CAFE Fundamentals: CommunicationBeans and Agents.http://www.java.net/blog/binod/archive/2010/01/04/sailfin-cafe-fundamentals-communicationbeans-and-agents
<!-- 2968 | 6 --><img src="/images/people/binod.jpg" border="0", align="left" /><div>
<p><a href="http://jcp.org/en/jsr/detail?id=289">SIP Servlets</a> provide a server side Java abstraction to SIP protocol and it is based on familiar servlet model. This enables an application developer to use Java servlet programming to write Converged applications. What exactly is the meaning of &quot;converged applications&quot;? SIP Servlet Specification explains this as follows</p>
<blockquote><p> &quot;While the SIP Servlet API can certainly be implemented independently of the HTTP Servlet API, it is expected that many interesting services will combine multiple modes of communication, for example, telephony, Web, email, instant messaging and other server side components like Web services and other Java EE interfaces.&quot; </p></blockquote>
<p> SIP Servlet specification defines SIP Application Session, which is a session that holds child protocol sessions (Http Session and Sip Sessions). The lifecycle of this Application Session is defined by the application itself. Thus it provides a flexible mechanism to share data between HTTP and SIP Sessions on an application defined scope. SIP Servlets also enable Java EE components to compose and send SIP requests as per RFC 3261.</p>
<p>SIP Servlets is one step in the right direction. I.e it provides a way to write applications that mixes SIP with other Java EE technologies. However, this forces application developer to learn SIP protocol. That would take the developer to the SIP RFC hell. Take a look at this <a href="http://www.ietf.org/rfc/rfc5411.txt"> RFC to list SIP RFCs</a> and imagine an average web developer starting to write SIP applications.</p>
<p><a href="http://en.wikipedia.org/wiki/The_Hitchhiker's_Guide_to_the_Galaxy">H2G2. Dont Panic!</a></p>
<p>With that introduction, lets see how does <a href="http://sailfin-cafe.dev.java.net">SailFin CAFE</a> simplifies the SIP application development.</p>
<p><b>Communication Beans</b></p>
<p>SailFin CAFE provides what is called &quot;Communication Beans&quot;. <a href="http://www.java.net/blog/binod/archive/2009/10/27/writing-your-first-im-server-using-sailfin-cafe">Essentially they are stateless POJOs that are annotated appropriately</a>. The main difference is that, the bean handles the SIP protocol (and many other telco industry specifications from OMA, 3GPP and IETF) by default and thus hides it from the developer. The developer can then write his logic to modify the behavior of Communication Beans. This is done from the perspective of modifying the behavior of &quot;communication&quot; it is handling rather than SIP protocol itself. By default the CommunicationBean will act as a simple B2bUA. Take a look at this <a href="http://www.java.net/blog/binod/archive/2009/10/01/writing-your-first-sailfin-cafe-application">2-party call</a> and this <a href="http://www.java.net/blog/binod/archive/2009/10/27/writing-your-first-im-server-using-sailfin-cafe"> instant messaging</a> examples for details.</p>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/comm-bean_0.png" /></p>
<p>A CommunicationBean can contain annotated methods to handle different events in the Communication. Take a look at this example, which creates a <a href="http://www.java.net/blog/binod/archive/2009/10/18/sailfin-cafe-implementing-simple-conference-application">Conference from the incoming call</a>. Effectively this converts the incoming two party call to a conference. Under the hood, CAFE would use a JSR 309 resource adapter to create the media mixer with a media server and do the necessary SDP negotiation. Whenever each event (annotated method) gets executed, the injected <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/CommunicationContext.html">CommunicationContext</a> would provide the relevent objects to the CommunicationBean implementation. Such objects are the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Communication.html">Communication</a> Object, The <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/Participant.html">participant</a> which invoked the event, Instance of Message (for example a <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/DtmfSignal.html">DtmfSignal</a> or <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/TextMessage.html">TextMessage</a>). etc.</p>
<p><b>Convergence in CAFE and Agents.</b></p>
<p>A <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/CommunicationSession.html">CommunicationSession</a> object is injected into HTTP Servlets and CommunicationBeans (When we have Java EE 6 based SIP Servlet containers, this would also work on all kind of Java EE artifacts. Thanks to JCDI). An application can use this object to create any kind of Communication. Different entities in a communication (eg: Communication, Participant, RegistrationProcedure) etc have different lifecycles and there might be different events happening pertaining to these entities. A converged application might need to execute logic based on such events. For example, in a music player application, when the communication gets <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/CommunicationEvent.Type.html#ESTABLISHED">&quot;established&quot;</a>, the application might want to play a music. Similarly, in a conference application, when the host of the communication <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/bean/ParticipantEvent.Type.html#JOINED">&quot;joins&quot;</a> the conference, recording might be activated. Obviously these events will be invoked in the CommunicationBean. But then how will application write their logic linking all these events?</p>
<p><img alt="" src="http://weblogs.java.net/sites/default/files/cafe-agent.png" /></p>
<p>To handle with this, CAFE provides the ability to attach &quot;Agent&quot; objects for different Communication artifacts. An &quot;Agent&quot; is an application defined object that contains data and logic specific to the application. An Agent can be Attached to a Communication or a Participant (or the same Agent can be attached to both). Now, application invoke the Agent to perform the application specific logic whenever the event occurs. Given Communication artifacts are accessible both from Web Application and from the CommunicationBean, the Agent facilitate Converged application development in an organized way.</p>
<p>A music player example application is <a href="https://sailfin-cafe.dev.java.net/source/browse/sailfin-cafe/trunk/cafe-samples/musicstore/">checked in here</a>, which uses most of the functionalities mentioned in this blog. Post any questions you may have of <a href="mailto:dev@sailfin.dev.java.net">dev@sailfin.dev.java.net</a>. Or follow SailFin on twitter at <a href="http://www.twitter.com/sailfincs" title="http://www.twitter.com/sailfincs">http://www.twitter.com/sailfincs</a>.</p>
</div>
http://www.java.net/blog/binod/archive/2010/01/04/sailfin-cafe-fundamentals-communicationbeans-and-agents#commentsBlogsGlassFishJ2EEJava EnterpriseWeb ApplicationsMon, 04 Jan 2010 14:48:12 +0000binod338085 at http://www.java.netV3, Java EE 6 and SIP Servlets http://www.java.net/blog/binod/archive/2009/12/10/v3-java-ee-6-and-sip-servlets%20
<!-- | 0 --><p>Much awaited <b>GlassFish V3 is released today</b>. The modular, OSGI based Java EE 6 product has been making headlines for some time now. I have been experimenting V3 for some time now, basically from the POV of <b>SailFin</b> and SIP Servlets. Here are some items on top of mind that are relevant for SIP Servlets and next SailFin release.
</p>
<ol>
<li>Doing a modularized OSGI based SIP Servlet Container and <b>SailFin CAFE</b> is probably the most obvious item</li>
<li>Java EE 6 has standardized module names and application names. That will be applicable for SIP Servlets, especially since <b>application composition in SIP Servlets is based on SIP module names</b>.</li>
<li>The new JNDI namespaces introduced in Java EE 6, especially the module name is quite applicable for SIP Servlets. The current SIPFactory and SIPSessionsUtil lookup should benefit from the newly introduced namespaces (global, module,app) etc along with namespaces. Take a look at <b>Java EE 6</b> specification (chapter EE5.2.2) for more details.</li>
<li>The servlet extensibility introduced in the latest servlet specification is certainly applicable for SIP Servlets also, especially since <b>Converged Application Frameworks are on the rise</b></li>
<li>Asynchronous servlets and EJBs would help converged application development, since communication protocols are much more asynchronous than the Java EE technologies and hence it will be a good mechanism for integrating communication with </li>
<li>CDI (JSR 299) is certainly important for SIP Servlets as well. Looking forward to using it for SailFin CAFE</li>
</ol>
<p>
Are there any thing else, you would like to see in SailFin v3? Do send e-mails to sailfin mailing lists (<b>users@sailfin.dev.java.net</b>).</p>
http://www.java.net/blog/binod/archive/2009/12/10/v3-java-ee-6-and-sip-servlets%20#commentsFri, 11 Dec 2009 19:00:00 +0000binod338136 at http://www.java.netCAFE Instant Messaging Demo with Google Translate API.http://www.java.net/blog/binod/archive/2009/11/27/cafe-instant-messaging-demo-google-translate-api
<!-- 20 | 6 --><img src="/images/people/binod.jpg" border="0", align="left" /><div>
<p><br><br />
<img alt="" src="http://weblogs.java.net/sites/default/files/im-translated.png" /><br />
<br></p>
<p>
CommunicationBean defined in <a href="http://sailfin-cafe.dev.java.net">SailFin CAFE</a> act as the listener for any communication events. For example, in case of instant messaging between<br />
two SIP clients, a CommunicationBean would intercept all the messages. These messages are available to the CommunicationBean implementation<br />
as POJO. That also mean that, you can implement the business logic in the CommunicationBean.
</p>
<p>
This example demonstrates using google translate APIs to translate the IM between two SIP users. <a href="http://code.google.com/p/google-api-translate-java/">There is a nice and simple java client</a> for the google translate API that I use for this sample. <a href="http://gist.github.com/244094">Take a look at this gist</a> showing the CommunicationBean implementation. The translation is based on the language set in in the HTTP Servlet.
</p>
<script src="http://gist.github.com/244094.js"></script><p>
Complete <a href="http://github.com/binod/cafe-google-translate">application and steps to execute are available here</a>. And here is the <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/index.html">javadoc of the SailFin CAFE</a>.
</p>
</div>
<p><br><br></p>
<hr/>
<script type="text/javascript">
tweetmeme_source = 'binodpg';
</script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script><hr/>
http://www.java.net/blog/binod/archive/2009/11/27/cafe-instant-messaging-demo-google-translate-api#commentsBlogsGlassFishInstant MessagingJ2EEJava EnterpriseFri, 27 Nov 2009 16:38:21 +0000binod328316 at http://www.java.netTyping Detection in SailFin CAFE http://www.java.net/blog/binod/archive/2009/11/16/typing-detection-sailfin-cafe
<!-- 17 | 105 --><div>
<br><br />
<img alt="" src="http://www.java.net/sites/default/files/im-cafe.png" /><br />
<br></p>
<p>
<a href="http://www.ietf.org/rfc/rfc3994.txt">RFC 3994</a> standardized how <a href="http://www.ietf.org/rfc/rfc3261.txt">SIP</a> applications implement "Indication of Messages" or "Typing detection" at protocol level. <a href="https://sailfin-cafe.dev.java.net/">SailFin CAFE</a> provides a simple way to detect typing using a Communication Bean. Also a web application can send a "Message Indication" to a SIP client.
</p>
<p>
Here is the code that implements receiving Instant Messages and Message Indication from a SIP client.
</p>
<pre class="prettyprint"><code>@CommunicationBean<br />public class SimpleCommsBean {<br /><br /> @Context CommunicationContext ctx;<br /><br /> @CommunicationEvent(type=CommunicationEvent.Type.MESSAGEINDICATION)<br /> void handleMessageIndication() {<br /> IMConversation conv = (IMConversation) ctx.getCommunication();<br /> MessageIndication msg = (MessageIndication) ctx.getMessage();<br /> System.out.println("Message State : " + msg.getState());<br /> System.out.println("Next Message Type : " + msg.getNextMessageType());<br /> }<br /><br /> @CommunicationEvent(type=CommunicationEvent.Type.MESSAGEARRIVED)<br /> void handleMessage() {<br /> IMConversation conv = (IMConversation) ctx.getCommunication();<br /> TextMessage msg = (TextMessage) ctx.getMessage();<br /> System.out.println("Received Message" + msg.getText());<br /> }<br />}</code></pre>
<p>
In the code above, the first event gives an indication about the message (eg: whether the user is actively typing, what is the type of next message etc).<br />
In the next event, the application receives the actual message. Both these , on a typical SIP Servlet application , would be received as the content of a SIP<br />
message and application would need to interpret the content. Message Indication is an xml document, which would otherwise need to be parsed by the SIP Servlet. Here the CAFE framework<br />
handles the parsing the message content and provides it as an appropriate POJO to the application.
</p>
<p>
Similarly, a servlet or JSP would send a Message Indication or Text Message to SIP client by creating an IMConversation. Here is the sample<br />
servlet code that send IM message.
</p>
<pre class="prettyprint"><code> @Context CommunicationSession session;<br /><br /> @Override<br /> protected void doGet(HttpServletRequest request,<br /> HttpServletResponse response) throws ServletException,<br /> java.io.IOException {<br /> <br /> java.io.PrintWriter out = response.getWriter();<br /> String party1 = request.getParameter("party1");<br /> String party2 = request.getParameter("party2");<br /> try {<br /> out.println("<html>");<br /> <b>IMConversation conv = session.createIMConversation(party1);<br /> conv.addParticipant(party2);<br /> conv.createMessageIndication().send();<br /> conv.createTextMessage("Hi There").send();</b><br /> out.println("IMConversation started between " + party1 + "and" + party2);<br /> } catch (Exception e) {<br /> out.println(e);<br /> }</code></pre><br />
For more information take a look at the javadoc for <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/IMConversation.html">IMConversation</a>, <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/TextMessage.html">TextMessage</a> and <a href="http://download.java.net/javaee5/sailfin-cafe/v1/apidocs/org/glassfish/cafe/api/MessageIndication.html">MessageIndication</a>.
</div>
<p><br><br></p>
<hr/>
<script type="text/javascript">
tweetmeme_source = 'binodpg';
</script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script><hr/>
http://www.java.net/blog/binod/archive/2009/11/16/typing-detection-sailfin-cafe#commentsBlogsMon, 16 Nov 2009 16:22:36 +0000binod319025 at http://www.java.netAdding Communication capabilities to JSPs (SailFin CAFE)http://www.java.net/blog/binod/archive/2009/11/08/adding-communication-capabilities-jsps-sailfin-cafe
<!-- | 0 --><p>
Hope you have read <a href="http://weblogs.java.net/blog/binod/archive/2009/11/04/sailfin-cafe-adding-communication-capabilities-web-applications-made-v">my last blog</a> on using <a href="http://sailfin-cafe.dev.java.net">SailFin CAFE</a> with web applications. <a href="http://blogs.sun.com/mohitg/">Mohit</a> has added an entry on <a href="http://blogs.sun.com/mohitg/entry/sailfin_cafe_click_to_call">how to enable Communication capabilities in JSPs</a>. The approach is exactly same except that the <code class="prettyprint">CommunicationSession</code> object is available as a session attribute.
</p>
<p>
Take a look!
</p>
http://www.java.net/blog/binod/archive/2009/11/08/adding-communication-capabilities-jsps-sailfin-cafe#commentsBlogsGlassFishJ2EEJava EnterpriseOpen SourceWeb ApplicationsMon, 09 Nov 2009 03:26:49 +0000binod312553 at http://www.java.net