Skip to main content

REST'ing @ SailFin CAFE

Posted by rampsarathy on January 25, 2010 at 6:43 AM PST

Converged (Http/SIP) applications gives users the flexibility of creating or accessing information about their communications (call/conferences/im ...) over the web. To make this possible a typical converged application would contain an entry point for all the Http requests, which is mostly an Http Servlet. This servlet would return back appropriate responses by accessing the corresponding communication (SIP) sessions. Every communication application that is deployed would need one (or more) Http servlets in order to support Web clients (as shown in figure 1). But, the fact is that most of the operations that are required by web clients are quite similar and do not differ much on the server side with respect to the implementation of the http servlet. Common tasks a web client might do include setting up a call (CallSetup), querying status of calls, terminating a call, modifying a call etc... From a developers perspective its desirable if the converged application development framework provides a means of exposing these common tasks rather than having to write a htttp servlet for it. It also helps if these are exposed as an API, that is portable as well as open standards compliant. 

 

1

Figure 1

 

SailFin CAFE solves this problem by exposing these through a REST API. When a CAFE application is deployed (with some information added to web.xml descriptor), all the regular tasks of creating and managing the communication are exposed as REST URIs  and the required resources provisioned automatically. Build v1-b24  of CAFE  comes with REST resources implementation of Call and Conference. By including the following lines in the web.xml deployment descriptor the REST resources are provisioned and made available for your CAFE application

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>CAFE REST Service</servlet-name>
        <servlet-class>
  com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>org.glassfish.cafe.rest.impl</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CAFE REST Service</servlet-name>
        <url-pattern>/*</url-pattern>
        </servlet-mapping>
</web-app>

The REST resources are implemented using the Jersey JSR 311 (Figure 2) implementation that is bundled with SailFin. The deployment descriptor above indicates that the CAFE REST resources that are available under the org.glassfish.cafe.rest.impl package should be made availble through Jersey. Once a CAFE application with such a deployment descriptor is deployed, Web clients would be able to access the  REST URIs, for their application

 

2
Figure 2

 

For e.g to create a call from the  web client (assuming the SIP UAs of Alice and Bob have registered)

http://host:port/{contextroot}/resources/calls/{server/client}/call/{callid}?from=alice@example.com&to=bob@example.com

where contextroot is the context root of the deployed application and callid is the callid for the call. And server/client refers to the nature of the APIs. Currently only server APIs are available , and these are synchronous where the client has to wait for a response on the same connection.

For a complete list of REST URIs and the content schema please see

http://download.java.net/javaee5/sailfin-cafe/v1/restdocs/

The WADL is available here

http://download.java.net/javaee5/sailfin-cafe/v1/restdocs/cafe-rest.wadl

Currently, (at the time of writing this article) only sychronous (server API, client has to wait for the response on the same connection) support is available, keep watching this space, i will update as soon as we have async APIs.

 

AttachmentSize
rest-1.png14.7 KB
rest-2.png18 KB
Related Topics >>