Network Deployment (Distributed operating systems), v8.0 > Reference > Developer best practices


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, 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);
        }


Browse all SIP topics
SIP servlets


Related


SIP SipSession and SipApplicationSession classes
Example: SIP servlet simple proxy
Example: SIP servlet SendOnServlet class
Example: SIP servlet Proxy servlet class
SIP proprietary header fields

+

Search Tips   |   Advanced Search