Sailfin in detail : Part 1 app-name


Let me start off by stating the motivation behind this blog. JSR289 has gone through some changes in the way @Resource annotations are used to inject SipFactory, SipSessionsUtil and SipTimer objects into a Sip Servlet or a Java EE components like EJB, HTTP Servlet or an MDB. In the final release , the syntax for doing so has been finalized as


@Resource( name="sip/<app-name>/SipFactory) SipFactory sf;


where app-name is the name of the application whose SipFactory / SipSessionsUtil or SipTimer is to be injected. The app-name is a configuration element which is specified in the deployment descriptor sip.xml.

In case of Sailfin , we also derive the app-name if its not specified in the deployment descriptor. The purpose of this blog is to explain how app-name is treated in Sailfin.



Lets start with the rules first !






• There is an app-name available for each application that is deployed in Sailfin. This is true both for application that correspond to the SIP Servlet v1.1 specification and those which correspond to the SIP Servlet v1.0 specification.


    Case I : There is no app-name specified in the sip.xml ( deployment descriptor)
    1. In this case the app-name is the name of the archive without the extension. i.e. if the archive is named as foo.sar , then the app-name is derived as foo .
    2. If the SIP Application is bundled within a Java EE Enterprise Application, then the app-name is derived as / . i.e. If the SIP Application, foo.sar is bundled within an Enterprise Application named as barApp.ear , the app-name corresponding to foo.sar is derived as barApp/foo


    Case II: There is an app-name specified in the sip.xml ( deployment descriptor)
    1. In this case the app-name is taken as it is defined in the sip.xml. This is true for both standalone SIP Applications and SIP Applications bundled within an Enterprise Application.
    2. A key assumption made here is that the app-name is not duplicated.

• In both these cases the Application Router would use the app-name specified or derived by Sailfin to identify the application.


Now lets look at a simple example to see how these rules are applied in a simple SIP Application !


Sample 1
The first sample is a Converged SIP Application which injects a SipFactory into a Sip Servlet using @Resource annotation. This sample will be used to show both Case I and Case II for a standalone SIP Application.

The sample has a SIP Servlet which listens to SIP REGISTER requests and creates a SipApplicationSession, using SipFactory. The SipFactory is injected using a @Resource annotation, and is available in the JNDI namespace as follows:
sip/<app-name>/SipFactory

Note that to inject the SipFactory in the SIP Servlet in a standalone SIP Application , we do not need to use the name attribute, since there is only one SipFactory instance available per SIP application.

A look at the JNDI tree ( using the Sailfin Admin Console) show how the SipFactory JNDI name is constructed using either a derived app name ( Case I ) or using the app-name specified in the sip.xml ( Case II)



Case I :

• The JNDI tree : Note the JNDI name of the SipFactory, SipSessionsUtil and SipTimer objects, have the app-name as the name of archive in which the SIP Application is packaged. i.e. ConvergedSipApplication

• The sip.xml : Note that the app-name attribute is missing.



Case II :

• The JNDI tree : Note the JNDI name of the SipFactory, SipSessionsUtil and SipTimer objects, have the app-name as the value of the app-name specified in the sip.xml.

• The sip.xml : Note that the app-name attribute is present and specifies the app-name as ConvergedApp

Sample 2

In this sample, we add the SIP Application developed above, to an Enterprise Application. Hence we have a Converged Enterprise Application , with an EJB module and SIP Application within. The use case here is
A SIP Servlet listens to REGISTER requests, creates a SipApplicationSession and adds the SipURI received from the UAC as an attribute in the SipApplicationSession.
An HTTP Servlet would then invoke an EJB , which in turn retrieves the same SipApplicationSession using a key, and then get the attribute that was set in the SIP Servlet. The SipApplicationSession is looked up using a SipSessionsUtil object, an instance of which is injected into the EJB using the @Resource annotation.

Hence as you can see we have an EJB and SIP Application co-located within an Enterprise Application archive and sharing a SipFactory and SipSessionsUtil instance. In the next few steps we see how we use the app-name to get hold of the SipFactory or SipSessionsUtil instance within the EJB.

The app-name used will be dependent on the condition that we have specified the app-name in the sip.xml or not.

Case I
The app-name is not specified in the sip.xml. Hence the app-name is derived from the archive name of the EAR file appended with the archive-name of the SIP Application.

• The JNDI Tree show the JNDI name of the SipFactory, SipSessionsUtil and SipTimer objects.

• The @Resource annotation in the EJB used to inject the SipFactory and/or SipSessionsUtil has the name attribute specified, with value of this attribute being
sip/ConvergedEnterprise/ConvergedSipApplication/SipFactory





 
@Stateless
public class TalkBackBeanBean implements TalkBackBeanLocal {

   
@Resource(name="sip/ConvergedEnterprise/ConvergedSipApplication/SipFactory") SipFactory sf;
   
@Resource(name="sip/ConvergedEnterprise/ConvergedSipApplication/SipSessionsUtil") SipSessionsUtil ssu;

    public String findWho() {

      SipApplicationSession sas = ssu.getApplicationSessionByKey("CSA",false);
       return (String) sas.getAttribute("newReg");
    }

}





Case II
In this case , the app-name is specified in the sip.xml ( as in the earlier sample) and the value of the app-name element is ConvergedApplication
• The sip.xml snippet shows the app-name being specified.

• The @Resource annotation in the EJB ( TalkBackBean ) uses the app-name specified in the sip.xml as the name attribute.





 
@Stateless
public class TalkBackBeanBean implements TalkBackBeanLocal {

   
@Resource(name="sip/ConvergedApplication/SipFactory") SipFactory sf;
   
@Resource(name="sip/ConvergedApplication/SipSessionsUtil") SipSessionsUtil ssu;

    public String findWho() {

      SipApplicationSession sas = ssu.getApplicationSessionByKey("CSA",false);
       return (String) sas.getAttribute("newReg");
    }

}

I am attaching sources for the sample applications that I have used in this blog.
• Converged Enterprise Application (Case I) src | binary

• Converged Enterprise Application (Case II) src | binary

If you try it out, build it using NetBeans and deploy it using the Admin Console of Sailfin.

Comments:

Post a Comment:
Comments are closed for this entry.
About

prasads

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today