This example is a simple SIP proxy servlet. The proxy servlet will forward all SIP messages from the caller client to the callee server.
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."); } }
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).
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.
Follow these instructions to deploy and run the example.
Click File->Open Project and navigate to the location where you downloaded and expanded the SimpeProxy example.
Select SipProxy and click Open Project.
Right-click on SipProxy in the Projects pane and click Run.
Be sure you have installed the SIPp test application, as described in SIPp Test Application.
In a terminal, enter the following command to start the SIPp server on port 5090:
% sipp -sn uas -p 5090
In a new terminal enter the following command to start the SIPp client on port 5080:
% sipp -sn uac -rsa 127.0.0.1:5060 -p 5080 127.0.0.1:5090
You should now see the messages from the client get returned by the server, with the SipProxy application acting as a proxy between them.