Course Data project

A JISC funded project aimed at improving course-related data at Sussex University

New features of Java EE 6 used in this project (part 2)



As mentioned in my last post, the XCRI-CAP project has allowed us to use many of the new features of Java EE 6. One of the new features we’ve been able to implement is the RESTful web service support via JAX-RS.  Previously we have implemented JAX-WS web services by turning EJB Session beans into web services. For the XCRI-CAP project, we have implemented a RESTful service using the Jersey implementation of JAX-RS.

JAX-RS makes it very easy to produce a RESTful web service. The first thing to do is to register the Jersey REST servlet with the application’s web.xml.


This Servlet will be used for any request mapped to /CourseCatalog.

Next, we can create an EJB that will act as the actual REST service. Using the @Path annotation at the top of the Session bean will control which requests will be handled by the class. In this instance, I want all requests to /CourseCatalog to be handled by this Session bean:

 * REST Web Service
 * @author rjb41
public class XCRI_CAPRestService {

Next we can write a method that will receive the RESTful requests. The following method handles Rest parameters sent to the /CourseCatalog/rest/foo/bar URL:

     * Returns the REST XML representation of the service 
     * @todo specify search criteria
     * @param cId
     * @return 
    public String getXCRIXml(@PathParam("name") String name, @PathParam("value") String value) {
        if (!(new File(xcriSession.getSearchCourseFileName())).exists()) {
        return outputDocument(xcriSession.searchCatalog(name, value)).toString();

This method treats the first argument as the parameter name and the second as the value to search on, e.g.
XCRI-CAP/CourseCatalog/rest/subject/European would return all courses that contain the word European (the application is actually querying the XML for nodes that end in subject and contain the word ‘European’).

Of course we can do more complex URL searches but for the purposes of demonstration, this shows what is possible.

There are plenty of good tutorials to be found on line, here is the official Oracle documentation:

Leave a Reply