Giter VIP home page Giter VIP logo

camel-cxfrs-example's Introduction

Camel CXF Rest Example with JSON

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

About The Example

The Example contains 3 modules

  1. CXFRS Service Module
  2. CXFRS Common Module
  3. 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.

  1. Country.java
  2. 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

  1. Main.java
  2. 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

  1. Calls the cxf service by passing country code and obtains a country in JSON format
  2. unmarshals the JSON obtained to POJO and identifies whether the response is correct
  3. marshals the correct response to POJO
  4. saves the pojo to File.

#####Setting up the Example

  1. check out the example

  2. 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

  1. deploy the cxf-rest war available in cxf-rest-service module to your favrioute web container

  2. Hit http://localhost:8080/cxf-rest/services/country/in
    in your favrioute browser. This will tell whether web context is up or not.

  3. execute mvn exec:exec from client module

camel-cxfrs-example's People

Contributors

santoshjoshi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.