Search
The Open Source SLEE and SIP Server

sf-api

Create SIP Server

Operation of SSF

When starting, SSF is processed as follows.

  • Get user's POJO from ApplicationContext
  • Register the event mapping (for SIP events) from annotation of POJO that handles SIP events.

When SSF receives the SIP events, basic sequernce is below.

Basic sequence
  1. Create the event for handler.
  2. Check the created event, and get the handler that corresponds to event mappings.
  3. Dispatch the event to the handler.
  4. When error occurred, process the error by ErrorHandler.

Next, create the POJO that is event handler for this sequence.

Create the event handler.

Create the bean that receives the SIP event(s).

RegistrarHandler

Create the event handler that receives the REGISTER request for registrar.

@Component
public class RegisterHandler {

    @Resource
    RegistrarBean registrarBean;
    
    @Resource
    CheckRequireBean requireBean;
    
    @SipServletRequestMapping(methods = { "REGISTER" })
    public void handleRequest(SipServletRequest req)
            throws ServletParseException, IOException {
        // start
        this.requireBean.handleRequest(req);
        if (!req.isCommitted()) {
            this.registrarBean.handleRegister(req);
        }
        // end
    }
}

Description of each annotation

  • @Component

    This annotation is provided by SpringFramework.

    See the below document. 3.12.1. @Component and further stereotype annotations

  • @Resource

    This annotation is set to inject values to fields.

  • @SipServletReqeustMapping

    This is a original annotation of SSF. In this case, this method is called by SSF when received SIP REGISTER reuest. And arguments of method are injected by SSF.

This handler processes the below, when receives REGISTER request.

  1. Check the Require header.
  2. Check the REGISTER request,register the location of UE, and send 200/REGISTER response.

Please refer the source about details of each bean.

ProxyHandler

Create the handler for Proxy.

@Component
public class ProxyHandler {
    private Logger logger = LoggerFactory.getLogger(ProxyHandler.class);
    @Resource
    ProxyBean proxyBean;
    @Resource
    CheckRequireBean checkRequire;
    
    @SipServletRequestMapping(methods = { "INVITE", "OPTIONS", "UPDATE",
            "MESSAGE", "PUBLISH" })
    public void handleRequest(SipServletRequest req) throws Exception {
        // start
        if (logger.isDebugEnabled()) {
            logger.debug("handleResquest:[req=" + req + "]");
        }
        checkRequire.handleRequest(req);
        if (req.isCommitted()) {
            return;
        }
        proxyBean.startProxy(req);
        // end
    }
    @SipServletResponseMapping(status = "1xx")
    public void handleProvisionalResponse(SipServletResponse res) {
        if (logger.isDebugEnabled()) {
            logger.debug("handleProvisionalResponse:[res=" + res + "]");
        }
    }
    @SipServletResponseMapping(status = "2xx")
    public void handleSuccessResponse(SipServletResponse res) {
        if (logger.isDebugEnabled()) {
            logger.debug("handleSuccessResponse:[res=" + res + "]");
        }
    }
    @SipServletResponseMapping(status = "3xx")
    public void handleRedirectResponse(SipServletResponse res) {
        if (logger.isDebugEnabled()) {
            logger.debug("handleRedirectResponse:[res=" + res + "]");
        }
    }
    @SipServletResponseMapping(status = { "4xx", "5xx", "6xx" })
    public void handleErrorResponse(SipServletResponse res) {
        if (logger.isDebugEnabled()) {
            logger.debug("handleErrorResponse:[res=" + res + "]");
        }
    } 

Defines the target SIP request and SIP response for the Proxy.

When receives a request, transfer to the Bean to proxy the request. When receive a response, print the debug log.

In next, the configuration of handlers is registered to Spring ApplicationContext.

Update the Spring configuration

Update the Spring configuration for definition of created beans.

  • common-beans.xml

    Add the below configuration for common beans using in each Web and SIP application

  <context:annotation-config/>
  <context:component-scan base-package="com.oki.test.services.impl" />

This package includes below beans.

  • UserManagementService

    This class is used to manage users in SIP Server and managed as singleton scope by Spring.

  • LocationService

    This class is used to manage the contact information of users and managed as singleton scope by Spring.

  • sip-dispatcher-servlet.xml

    Add the below configuration for SIP application.

  <context:component-scan base-package="com.oki.test.sip.sipserver" />

This package includes below beans.

  • ProxyHandler,RegistrarHandler

    Event handler for SSF.

  • CheckRequireBean

    Check the Require header, and send 420 response when the request includes unsupported extensions.

  • ProxyBean

    When receive requests, proxy them to the Contact information that acquired from LocationServie.

  • RegistrarBean

    This bean processes according to RFC3261 10.3 (Processing REGISTER Requests).

    When receives REGISTER requests, register (or remove) Contact information to ( or from) LocationService, and send 200/REGISTER response that includes Contact information of user's AoR.

Please refer The Spring Framework - Reference Documentation 2.5.3. Annotation-based controllers about the context namespace.

You can get sources of the sample with the following command.

 $ svn co https://mobicents.googlecode.com/svn/trunk/frameworks/sip-servlets/ssf/sf-examples

Next page