The SIP Servlet Tutorial

Developing the SIP Servlet

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

@SipListener
@SipServlet
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.

SipErrorListener Methods

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