SIP SipServletRequest and SipServletResponse classes on Liberty

The SipServletRequest and SipServletResponse classes are similar to the HttpServletRequest and HttpServletResponse classes that are used when you develop web applications.

Each class gives you the capability to access the headers in the SIP message and manipulate them. Because of the asynchronous nature of the requests and responses, the SipServletRequest class also creates new responses for the requests. When you extend the doInvite method, only the SipServletRequest class is passed to the method. To send a response to the client, you must call the createResponse method on the Request object to create a response as shown in the following example:

protected void doInvite(SipServletRequest req) throws
 javax.servlet.ServletException, java.io.IOException {
	
	//send back a provisional Trying response
	SipServletResponse resp = req.createResponse(100);
resp.send();

Because of their asynchronous nature, SIP servlets can seem complicated; however, something as simple as the previous code sample sends a response to a client.

The following example shows a more complex SIP servlet. With the following method included in a SIP servlet, the servlet blocks all of the calls that do not come from the example.com domain.

protected void doInvite(SipServletRequest req) throws
 javax.servlet.ServletException, java.io.IOException {

//check to make sure that the URI is a SIP URI
	     if (req.getFrom().getURI().isSipURI()){
                 SipURI uri = (SipURI)req.getFrom.getURI();
                 if (!uri.getHost().equals("example.com")) {
                    //send forbidden response for calls outside domain
                    req.createResponse(SipServletResponse.SC_FORBIDDEN).send();
                    return;
                 }
              }
              //proxy all other requests on to their original destination
              req.getProxy().proxyTo(req.getRequestURI);
        }

For more information on these classes, see the SIP Servlet Specification 1.1, JSR 289.


Icon that indicates the type of topic Reference topic



Timestamp icon Last updated: Monday, 5 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-libcore-mp&topic=rwlp_sip_servclass
File name: rwlp_sip_servclass.html