SIP SipServletRequest and SipServletResponse classes

The SipServletRequest and SipServletResponse classes are similar to the HttpServletRequest and HttpServletResponse classes.

SipServletRequest and SipServletResponse classes

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, this class is also the place to create 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. For 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.

Here is a more complex example of a 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);
        }



Related tasks
Browse all SIP topics
SIP servlets
Related reference
SIP SipSession and SipApplicationSession classes
Example: SIP servlet simple proxy
Example: SIP servlet SendOnServlet class
Example: SIP servlet Proxy servlet class
Reference topic    

Terms of Use | Feedback

Last updated: Feb 19, 2011 5:25:36 AM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v610web&product=was-nd-mp&topic=rsip_servclass1
File name: rsip_servclass1.html