JBoss.orgCommunity Documentation

CDI Telco Framework User Guide

The Guide to the CDI Telco Framework


This manual uses several conventions to highlight certain words and phrases and draw attention to specific pieces of information.

In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. The Liberation Fonts set is also used in HTML editions if the set is installed on your system. If not, alternative but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later includes the Liberation Fonts set by default.

Four typographic conventions are used to call attention to specific words and phrases. These conventions, and the circumstances they apply to, are as follows.

Mono-spaced Bold

Used to highlight system input, including shell commands, file names and paths. Also used to highlight key caps and key-combinations. For example:

The above includes a file name, a shell command and a key cap, all presented in Mono-spaced Bold and all distinguishable thanks to context.

Key-combinations can be distinguished from key caps by the hyphen connecting each part of a key-combination. For example:

The first sentence highlights the particular key cap to press. The second highlights two sets of three key caps, each set pressed simultaneously.

If source code is discussed, class names, methods, functions, variable names and returned values mentioned within a paragraph will be presented as above, in Mono-spaced Bold. For example:

Proportional Bold

This denotes words or phrases encountered on a system, including application names; dialogue box text; labelled buttons; check-box and radio button labels; menu titles and sub-menu titles. For example:

The above text includes application names; system-wide menu names and items; application-specific menu names; and buttons and text found within a GUI interface, all presented in Proportional Bold and all distinguishable by context.

Note the > shorthand used to indicate traversal through a menu and its sub-menus. This is to avoid the difficult-to-follow 'Select Mouse from the Preferences sub-menu in the System menu of the main menu bar' approach.

Mono-spaced Bold Italic or Proportional Bold Italic

Whether Mono-spaced Bold or Proportional Bold, the addition of Italics indicates replaceable or variable text. Italics denotes text you do not input literally or displayed text that changes depending on circumstance. For example:

Note the words in bold italics above username, domain.name, file-system, package, version and release. Each word is a placeholder, either for text you enter when issuing a command or for text displayed by the system.

Aside from standard usage for presenting the title of a work, italics denotes the first use of a new and important term. For example:

CDI is the Java standard for dependency injection and contextual lifecycle management, led by Gavin King for Red Hat, Inc. and is a Java Community Process(JCP) specification that integrates cleanly with the Java EE platform. Any Java EE 6-compliant application server provides support for JSR-299 (even the web profile). It seemed a natural fit create a new framework based on CDI for the Telco world.

CDI-Telco-Framework (CTF) from Mobicents brings the power and productivity benefits of CDI into the Mobicents Sip Servlets platform providing dependency injection and contextual lifecycle management for converged HTTP/SIP applications. This new framework is intended to become a replacement for our previous Seam Telco Framework.

CTF mission statement is to simplify SipServlets development by introducing a component based programming model, ease of development by making available SIP utilities out of the box, and finally providing dependency injection and contextual lifecycle management to the SipServlets.


Container Support

CTF supports Mobicents Sip Servlets 1.x (JBoss AS5 - Tomcat 6.x) and Mobicents Sip Servlets 2.x (Tomcat 7.x).

CTF consists of

CTF starts by CDI enable your application providing all the advantages of CDI. While CTF can do more than that, just by adding the CTF listener in the web.xml or sip.xml of your application, you will be able to inject beans, produce beans and make use of the CDI contexts and scopes as you wish.

So for example, you can develop a sip registar module and make it available in the classpath of any application. From there you can inject the registar module and delegate registration request to it.

The SipRegistar could be like this:



       
    @ApplicationScoped
    public class SipRegistar {
    
        private static Logger logger = Logger.getLogger(SipRegistar.class);
        private static final String CONTACT_HEADER = "Contact";
        @Produces HashMap<String, String> users = new HashMap<String, String>();
        public void handleRegister(SipServletRequest req) throws ServletException,
                IOException {
            if(logger.isInfoEnabled()) {
                logger.info("Received register request: " + req.getTo());
            }
            int response = SipServletResponse.SC_OK;
            SipServletResponse resp = req.createResponse(response);     
            Address address = req.getAddressHeader(CONTACT_HEADER);
            String fromURI = req.getFrom().getURI().toString();
            int expires = address.getExpires();
            if(expires < 0) {
                expires = req.getExpires();
            }
            if(expires == 0) {
                users.remove(fromURI);
                if(logger.isInfoEnabled()) {
                    logger.info("User " + fromURI + " unregistered");
                }
            } else {
                resp.setAddressHeader(CONTACT_HEADER, address);
                users.put(fromURI, address.getURI().toString());
                if(logger.isInfoEnabled()) {
                    logger.info("User " + fromURI + 
                        " registered with an Expire time of " + expires);
                }
            }               
            resp.send();
        }
    }

Then in your application you can delegate all sip registration request to the SipRegistar module by doing:



       
    
    @Inject
    SipRegistar sipRegistar;
    
    public void processRegister(@Observe @Register SipServletRequest req){
        sipRegistar.handleRegister(req);
    }

What is actually happening, is that CTF will replace the AnnotationProcessor, in the case of Tomcat 6.x, or InstanceManager in the case of JBoss Web (JBoss AS5) and Tomcat 7.x with CTF version of AnnotationProcessor or InstanceManager that allows CTF to bootstrap and enable your converged application for dependency injection and contextual lifecycle management.

Being the fundamental feature of the framework, CTF will "CDI-enable" a converged application providing:

So CTF goes on step further to eliminate the Servlets layer from the SipServlet development. What that means is that the developer wont need to extend SipServlet anymore.

Pure Sip Servlets 1.1 specification programming model:



       
public class MySipMessagesHandlerClass extends SipServlet {
    //override SipServlet methods to handle incoming SIP Messages
}

CTF programming model:



       
public class MySipMessagesHandlerClass {
    //make use of annotations to specify which incoming SIP Messages your business is interested to handle
}

During bootstrap CTF will register a sip servlet that main’s responsibility will be to propagate SIP request and responses in the form of CDI events. Therefore the developer will be able to do the following:



       
    public class MySipMessagesHandlerClass {
        public void handleRegister(@Observes @Register SipServletRequest req)
             throws ServletParseException, IOException{
        
        if(logger.isInfoEnabled()) {
            logger.info("Received register request: " + req.getTo());
        }
        int response = SipServletResponse.SC_OK;
        SipServletResponse resp = req.createResponse(response);
        Address address = req.getAddressHeader(CONTACT_HEADER);
        String fromURI = req.getFrom().getURI().toString();
        
        int expires = address.getExpires();
        if(expires < 0) {
            expires = req.getExpires();
        }
        if(expires == 0) {
            users.remove(fromURI);
            if(logger.isInfoEnabled()) {
                logger.info("User " + fromURI + " unregistered");
            }
        } else {
            resp.setAddressHeader(CONTACT_HEADER, address);
            users.put(fromURI, address.getURI().toString());
            if(logger.isInfoEnabled()) {
                logger.info("User " + fromURI + 
                    " registered with an Expire time of " + expires);
            }
        }                                       
        resp.send();
    }

In the above code snippet you will notice the CDI component doesn't need to extend SipServlet anymore and just need to specify 2 annotations @Observes and @Register to tell the framework that it is interested in REGISTER SIP Messages. This provide you with type safety, auto completion feature in the IDE and let you handle SIP Messages in any component be it from your application or from a third party CTF-enabled library or module included in your application.

CTF will propagate the following SIP request methods:


To make use any of the CTF propagated request events, register the equivalent observer along with the SipServletRequest, that is:



       
public void handleUpdate (@Observes @Update SipServletRequest req){
}

and the following SIP responses:


To make use any of the CTF propagated response events, register the equivalent observer along with the SipServletResponse, that is:



       
public void handleErrorResponse (@Observes @ErrorResponse SipServletResponse resp) {
}

Note

As with all CDI observers, the name of the method is insignificant. The developer can choose any convenient method name as long as it uses the correct CTF Observer to receive the appropriate CTF event.

In order to get started with CTF, the only thing you have to do is to define few maven dependencies in your project and register the CTF listener in the sip.xml or web.xml or your application.

First dependency is Weld, the CDI reference implementation by JBoss and more specific the weld-servlet module.



       
       <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        

Second is the framework itself:



    
        <dependency>
            <groupId>org.mobicents.servlet.sip.weld</groupId>
            <artifactId>sip-servlets-weld</artifactId>
            <version>1.0.0.ALPHA1</version>
        </dependency>
        

The CTF listener that you have to register in your application is:

	
	<listener>
		<listener-class>
				org.mobicents.servlet.sip.weld.environment.servlet.SipServletsWeldListener
		</listener-class>
	</listener>
		

To get the source code along with the examples:

To build issue mvn clean compile package for each project and deploy accordingly

CTF have been tested and verified working in the following MSS containers:

With the advent of MSS 2.x, the Mobicents team made available asynchronous processing of requests feature in the world of SipServlets and demonstrated this feature with a new version of the traditional Click2Call example.

Now its time to get Click2Call one step further and demonstrate the CTF features with it.

In this new version of the Click2Call, the CDI programming model makes the application significant simpler by using beans as services. Redundant is the use of the ServletContext to store attributes such as registered users or calls. This is now being served by the CallStatusContainer and the SipRegistar modules. Several functions of the application are being delegated to beans also. Methods that need to fire an event are using the CDI event producer/observer model instead of a queue that was placed in the ServletContext and the SimpleSipServlet class is using the SipRegistar module to register users.

If you check out the Click2Call example you will notice the following major changes:

The drawing below will give you the general idea of the application’s interactions with the serveral modules and the CTF.


Note

MSS 2.x comes with Click2CallAsync predeployed, make sure you undeploy this application and apply the correct dar configuration before you deploy the new version of Click2Call.

In the examples of the framework you will find a version of Click2Call with CTF, suitable for servlet 2.5 containers such as Tomcat 6.0.29 and JBoss AS5.

Revision History
Revision 1.0Mon Apr 18 2011George Vagenas
First release CDI-Telco-Framework user guide