Right click in project explore, click "new" and click on "class" on the panel
package org.blogdemo.example; import java.io.Serializable; import javax.xml.bind.annotation.XmlRootElement; @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) {this.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) {this.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+"]"; } }
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="http://www.w3.org/2001/XMLSchema"> <xs:element name="stocktrading"> <xs:complexType> <xs:sequence> <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"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
REMOVE:
Transform XML file to POJO for further processing:
Configure source type of the file:
Configure Target Type:
Message:${body.name} has brought Stock ${body.stockId} with shares ${body.shares}
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
<version>2.15.1.redhat-620133</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Christina Lin</name>
<custId>A123456789</custId>
<vip>1</vip>
<stockId>XYZ</stockId>
<shares>11</shares>
</stocktrading>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Frank Jarrod</name>
<custId>F475678678</custId>
<vip>4</vip>
<stockId>ABC</stockId>
<shares>20</shares>
</stocktrading>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<multiple>
<stocktrading>
<name>John Osborn</name>
<custId>K34567854</custId>
<vip>1</vip>
<stockId>KUJ</stockId>
<shares>25</shares>
</stocktrading>
<stocktrading>
<name>Sarah Fox</name>
<custId>C3456767878</custId>
<vip>5</vip>
<stockId>SOU</stockId>
<shares>10</shares>
</stocktrading>
</multiple>