Developing the SIP Servlet

The SIP servlet is called SimpleProxyServlet, and extends the base SipServlet class and
implements the SipErrorListener and Servlet interfaces.

package com.ericsson.sip.servlet.example;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.sip.Proxy;
import javax.servlet.sip.SipErrorEvent;
import javax.servlet.sip.SipErrorListener;
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;



public class SimpleProxyServlet 
            extends SipServlet 
            implements SipErrorListener,Servlet {
    
    /** Creates a new instance of SimpleProxyServlet */
    public SimpleProxyServlet() {
    }
    
    
    protected void doInvite(SipServletRequest request) 
        throws ServletException, IOException {
    	 
        if (request.isInitial()) {

           Proxy proxy = request.getProxy();
           proxy.setRecordRoute(true);
	   proxy.setSupervised(true);
	   proxy.proxyTo(request.getRequestURI()); // bobs uri
          
        }
        
        System.out.println("SimpleProxyServlet: Got request:\n" + request);
    }
    
    
    protected void doBye(SipServletRequest request) throws 
				ServletException, IOException {
        
        System.out.println("SimpleProxyServlet: Got BYE request:\n" + request);
        super.doBye(request);
    }
    
    
    protected void doResponse(SipServletResponse response) 
        throws ServletException, IOException {
        
        System.out.println("SimpleProxyServlet: Got response:\n" + response);
 	super.doResponse(response);
    }
    
    
    // SipErrorListener
    
    public void noAckReceived(SipErrorEvent ee) {
         
        System.out.println("SimpleProxyServlet: Error: noAckReceived.");
    }
    
    public void noPrackReceived(SipErrorEvent ee) {
        
	System.out.println("SimpleProxyServlet: Error: noPrackReceived.");
    }
    
}

SIP Methods

In SimpleProxyServlet, you override several methods to respond to the main SIP methods.

  • doInvite- responds to INVITE requests.

In SimpleProxyServlet, upon receiving an INVITE request the servlet will create a javax.servlet.sip.Proxy instance, set some options, and proxy the request to the target SIP server.

  • doBye- responds to BYTE requests.

In SimpleProxyServlet, the servlet logs a message upon receiving a BYE message, and calls the doBye method of the parent class (javax.servlet.sip.SipServlet).

SipErrorListener Methods

Because SimpleProxyServlet implements the SipErrorListener interface, it must implement the following methods:

  • noAckReceived is invoked to notify the application that no ACK message was received for an INVITE transaction.
  • noPrackReceived is invoked when no PRACK message was received for a previously sent response.

[Previous|^gfpcy.txt] [Next|^gfpnl.txt]