My 2nd Camel Ride

  • After 1st Camel ride, you should have a running camel route, please stop it.

  • Now we are going to reformat the xml file to object, then object to JSON as output file format

  • Create a POJO named "TradeOrder"

Right click in project explore, click "new"  and click on "class" on the panel

package org.blogdemo.example;
import javax.xml.bind.annotation.XmlRootElement;

public class TradeOrder implements Serializable {
 private static final long serialVersionUID = -2812468154835390309L;
 String name;
 String custId;
 Integer vip;
 String stockId;
 Integer shares;
  Double cost;
  public String getName() {return name;}
 public void setName(String name) { = name;}
  public String getCustId() {return custId;}
  public void setCustId(String custId) {this.custId = custId;}
public Integer getVip() {return vip;}
public void setVip(Integer vip) { = vip;}
public String getStockId() {return stockId;}
public void setStockId(String stockId) {this.stockId =stockId;}
public Integer getShares() {return shares;}
public void setShares(Integer shares) {this.shares = shares;}
public Double getCost() {return cost;}
public void setCost(Double cost) {this.cost = cost;}
public static long getSerialversionuid() {
  return serialVersionUID;
public String toString(){
  return "name:["+name+"] custId:["+custId+"] vip:["+vip+"] stockId:["+stockId+"] shares["+shares+"]";

Add a file that indicates the input format

Create a fold by right click on example project in project explorer, click on "New" and choose "Folder"

Insert folder name as : xsdfiles

Right click on the "xsdfiles" folder, choose "New" and then click on "File"

Name the file as : stocktrading.xsd

And enter the following content:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="">
  <xs:element name="stocktrading">
        <xs:element type="xs:string" name="name"/>
        <xs:element type="xs:string" name="custId"/>
        <xs:element type="xs:byte" name="vip"/>
        <xs:element type="xs:string" name="stockId"/>
        <xs:element type="xs:byte" name="shares"/>

Modify the route to 

  • File Endpoint
    • Directory Name: myxml
    • Delete:true
  • Log Endpoint
    • Message: ${in.header.CamelFileName} with content -> ${body}
  • SetHeader
    • headerName: CamelFileName
    • language: simple
    • expression: ${date:now:yyyyMMddhhmmss}-read.xml



  • File Endpoint
    • Directory Name: donexml 

Transform XML file to POJO for further processing:

  •  Data Transformation                                                                                                         
    • Transform ID: transOrder
    • Dozer file path: transOrder.xml 
    • Source Type: XML
    • Target Type: Java


Configure source type of the file:

  • XML Type Definition: XML Schema
  • Source File: xsdfiles/stocktrading.xsd

Configure Target Type:

  • Target class: org.blogdemo.example.TradOrder
  • Log Endpoint
    • Message:${} has brought Stock ${body.stockId} with shares ${body.shares}

  • Marshal (JSON)
    • Unmarshal Type Name: org.blogdemo.example.TradeOrder
    • Library: Jackson
    • PrettyPrint: true



  • Log Endpoint                        
    • Message: JSON ${body}
  •  File Endpoint
    • uri: file://donexml                                                                                                       


Add the dependencies to your pom.xml






Remove the un-needed dependencies






Now you can start running it!

APPENDIX - order01.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
    <name>Christina Lin</name>

APPENDIX - order02.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
    <name>Frank Jarrod</name>

APPENDIX - order03.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
        <name>John Osborn</name>
        <name>Sarah Fox</name>

2nd Camel Ride completed!