#####Version Used:
- camel : 2.16.0
- CXF Version 3.1.3
Thie example demonstrates the use of apache camel to invoke a CXFRS service which returns JSON data.
The Client consumes this JSON data and then stores it into a file in json format
The Example contains 3 modules
- CXFRS Service Module
- CXFRS Common Module
- CXFRS Client Module
#####CXFRS Service Module
This exposes a CXF REST service where a client hits the
http://localhost:8080/cxf-rest/services/country/{countrycode}
url with some country code to get country details in JSON Format
The CountryService creates a rest interface as shown below.
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 POJOs that are shared by both client and service module.
- Country.java
- CountryResponse.java
service module populates it and client for consumes it.
#####CXFRS Client Module
This module calls a REST service hosted by service module with a country code like IN, CH, GE etc to get country information in JSON format, the JSON obtained is then marshalled to a country POJO and then save to a text file.
This module contains below java class
- Main.java
- CountryResource.java
CountyResource.java exposes an interface to the client for communication with the CXF REST Service defined by CXFRS service Module.
Main.java is basically for executing application.
A CXF Rest client has been created that hits the service hosted at
http://localhost:8080/cxf-rest/services
to fetch country details corrosponding to the passed country code.
A Camel route is written that executes as below
- Calls the cxf service by passing country code and obtains a country in JSON format
- unmarshals the JSON obtained to POJO and identifies whether the response is correct
- marshals the correct response to POJO
- saves the pojo to File.
#####Setting up the Example
-
check out the example
-
Go to cxf client module and adjust
< jaxrs:client id="restClient" address="http://localhost:8080/cxf-rest/services"
in cxf-services.xml
the service url to url where you want to deploy you rest application
3. execute
mvn clean install
-
deploy the cxf-rest war available in cxf-rest-service module to your favrioute web container
-
Hit http://localhost:8080/cxf-rest/services/country/in
in your favrioute browser. This will tell whether web context is up or not. -
execute mvn exec:exec from client module