Camel CXF Rest Example with JSON
This example demonstrates the use of Apache Camel to invoke a CXF Restful web service that returns JSON data. The client consumes this JSON data and stores it into a file in JSON format.
The example consists of three modules:
CXFRS Service Module:
This module exposes a CXF REST service where a client can hit the endpoint http://localhost:8080/cxf-rest/services/country/{countrycode}
with a country code to retrieve country details in JSON format.
The CountryService
interface defines the REST interface:
public interface CountryService {
@GET
@Path(value = "/country/{countryCode}")
@Produces(MediaType.APPLICATION_JSON)
public Response getCountry(@PathParam("countryCode") String countryCode);
}
CXFRS Common Module:
Country.java
and CountryResponse.java
classes which are populated by the service module and consumed by the client module.CXFRS Client Module:
To run this example:
cxf-services.xml
file in the CXF client module to the URL where you want to deploy your REST application.mvn clean install
cxf-rest
WAR available in the cxf-rest-service
module to your favorite web container.http://localhost:8080/cxf-rest/services/country/in
in your favorite browser.mvn exec:exec
from the client module to run the client application.