Skip to main content

What is new SIP Servlet 2.0 : Part I

Posted by binod on May 6, 2013 at 2:50 AM PDT

There are a number of topics JSR 359 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
planning to give an update on these features and others that we are working on in the expert group.

Lets start with SIP POJOs.

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 GenericServlet is more obvious for a SIP servlets.

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
such a SIP POJO.

@SipServlet
public class FooPOJO {
   @Invite
   public void handleInviteRequest(SipServletRequest request) {
   //...
   }
   @Invite
   public void handleInviteResponse(SipServletResponse response) {
   //...
   }
   @ProvisionalResponse
   public void handleSuccessResponse(SipServletResponse response) {
   //...
   }
}

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.

@Retention(RUNTIME)
@Target({METHOD})
@SipMethod("INVITE")
public @interface Invite {
}

As you can see, the @SipMethod meta annotation drive the logic.

@Retention(RUNTIME)
@Target({METHOD})
@SipResponseRange(begin = 100, end = 199)
public @interface ProvisionalResponse {
}

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.

@Retention(RUNTIME)
@Target({METHOD})
@SipResponseRange(begin = 200, end = 299)
@SipMethod("INVITE")
public @interface MySucessfulInviteResponse {
}

As you can see above, an application has used @SipMethod and @SipResponseRange for a custom annotation.

@Retention(RUNTIME)
@Target({METHOD})
@SipPredicate(InitialInvite.Predicate.class)
@SipMethod("INVITE")
public @interface MyInitialInvite {
  class Predicate implements javax.servlet.sip.Predicate {
    @Override
    public boolean apply(final SipServletRequest request) {
      return request.isInitial();
    }
  }
}

And in the above example, application has used a more powerful @SipPredicate to specify a custom filtering logic. Such custom annotations can now be used to annotate a SIP handler method.

More information (eg: method selection criteria) on this and also about all other features are available in the early draft. Join the sipservlet-spec java.net project to participate in the process.