Sailfin in detail : Part 2 annotated servlets



There are two ways in which we can define a SIP Servlet to be specific in a SIP Application. One of them is the traditional way of defining it in the sip.xml using the
> servlet <element and the other one is to use the @SipServlet annotation.

Once the annotation is used to define the servlet, then we need to have a mapping for the servlet,which, can be use the main-servlet mechanism or the servlet-mapping mechanism.Ideally if we use the main-servlet mechanism , we need not specify a sip.xml (deployment descriptor ) for defining servlets or servlet-mappings. In other words, if these are the only configuration data to be specified in the sip.xml , then we need not specify the sip.xml and instead use an annotation called @SipApplication to define a set of servlets to belong to an application.

This blog takes the example of an application and explains how @SipServlet annotation can be used alongwith the servlet-mapping mechanism and also explains the use the @SipApplication annotation.

@SipServlet
Lets start with the @SipServlet annotation. Any class which implements javax.servlet.sip.SipServlet and is annotated with @SipServlet is deemed as a Sip Servlet. There are attributes to this annotation that help in defining this Servlet.

name
used to specify the name . In the absence of this attribute the class name ( not he Fully Qualified , but just the plain class name ) is taken as the servlet-name.

applicationName
used to specify the app-name of the application to which this servlet belongs. Typically this is used to associate an annotated Servlet with a particular application. The value of the attribute is the app-name element in the sip.xml or the value of the applicationName attribute in the @SipApplication annotation.

description
Description for the servlet

loadOnStartup
This maps to the load-on-startup element in the sip.xml and specifies the order in which the servlet has to be loaded when the application is starting

All these attributes are optional. Now, lets look at this sample application which has two SIP Servlets, one of which is annotated and the other one is defined in the sip.xml. The annotated servlet has a mapping in the sip.xml.

The snippet below shows the definition of the RegisterServlet defined by an annotation.







@javax.servlet.sip.annotation.SipServlet

public class RegisterServlet extends javax.servlet.sip.SipServlet {

The snapshot below shows the sip.xml for defining the servlet-mapping for the RegisterServlet.

Since we did not specify the name attribute for the Servlet, the servlet-name used in the mapping is the classname of the SipServlet i.e. RegisterServlet. This servlet will be invoked for all REGISTER requests. Now lets says if we have defined the name attribute in the RegisterServlet, as name="Registrar" then we would need to mention the the servlet-name in the servlet-mapping element as "Registrar".

@SipApplication annotation

Now, lets take a look at how the @SipApplication annotation can be used. This annotation is a package level annotation and is defined in a package-info.java file. The package-info.java looks like this :
@javax.servlet.sip.annotation.SipApplication(
name="AnnotatedApp",
sessionTimeout=30,
distributable=true)
package net.java.servlet;

Note the package definition at the end of the file. This is the package for which this annotation is defined and all Sip Servlets within this package would be part of the SIP Application defined by this annotation. If there are other servlets in other packages that need to be added to this application , then the user needs to specify the name of the application in the applicationName attribute of the @SipServlet annotation. For example,

package com.example;

@SipServlet(applicationName="AnnotatedApp")
public class MySipServlet extends SipServlet {


adds the above defined SIP Servlet to the SIP Application named AnnotatedApp , even though it belongs to another package.

The @SipApplication annotation has the following attributes :
name
states the name of the application
displayName
maps to the < display-name > element in sip.xml
description
maps to the < description > element in sip.xml
distributable
maps to the < distributable > element in sip.xml
smallIcon
maps to the < small-icon > element in sip.xml
largeIcon
maps to the < large-icon > element in sip.xml
proxyTimeout
maps to the < proxy-timeout > element in sip.xml
sessionTimeout
maps to the < session-timeout > element in sip.xml
mainServlet
maps to the < main-servlet > element in sip.xml

The mainServlet element is used to specify a single servlet as the main-servlet and this will be the servlet invoked for all requests and the servlet defined as the main-servlet is responsible for delegating the incoming requests. In case the main-servlet is invoked the servlet-mapping mechanism is not used.
But that calls for another blog post !!


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