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.
- camel: 2.16.0
- CXF Version: 3.1.3
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:
- This module contains the POJOs shared by both the client and service modules.
- It includes
Country.java
andCountryResponse.java
classes which are populated by the service module and consumed by the client module.
-
CXFRS Client Module:
- This module calls the REST service hosted by the service module, providing a country code (e.g., IN, CH, GE) to retrieve country information in JSON format.
- The JSON response is then unmarshalled to a POJO and saved to a file.
To run this example:
- Check out the project from GitHub.
- Adjust the service URL in
cxf-services.xml
file in the CXF client module to the URL where you want to deploy your REST application. - Build the project using Maven:
mvn clean install
- Deploy the
cxf-rest
WAR available in thecxf-rest-service
module to your favorite web container. - Verify that the web context is up by hitting
http://localhost:8080/cxf-rest/services/country/in
in your favorite browser. - Execute
mvn exec:exec
from the client module to run the client application.