REST Services
About this task
The JAX-RS Section on the Apache CXF website provides a solid background to implementing REST services and also provides the latest information on the newest RESTful features offered by CXF.
For an example of working with a RESTful application in Eclipse and deploying the service to either Tomcat or the Talend Runtime Container, let's look at the JAXRS-Intro sample provided in the examples/talend folder of the Talend ESB installation. The demo lists the Persons who are part of a generic membership, and allows GETs to retrieve a single member or all members, POSTs to add members, and PUTs for updates to membership information.
The JAX-RS Server provides one service via the registration of a root resource class, MembershipService which relies on within-memory data storage. MembershipService provides a list of its members, which are individual Person objects containing name and age. New persons can be added to the MembershipService, and individual members can have their information updated. The RESTful client uses CXF JAX-RS WebClient to traverse all the information about an individual Person and also add a new child.
This sample consists of four subfolders:
Folder |
Description |
---|---|
client | This is a sample client application that uses the CXF JAX-RS API to create HTTP-centric and proxy clients and makes several calls with them. |
common | This directory contains the code that is common for both the client and the server. POJOs and the REST interface is kept here. |
service | This is the JAX-RS service holding the Membership root resources packaged as an OSGi bundle. |
war | This module creates a WAR archive containing the code from common and service modules. |
Working with a REST sample in Eclipse