public class ConverterRoute implements RoutesBuilder {
public void addRoutesToCamelContext(CamelContext context) throws Exception {
Tracer tracer = new Tracer();
tracer.setTraceOutExchanges(true);
// we configure the default trace formatter where we can
// specify which fields we want in the output
DefaultTraceFormatter formatter = new DefaultTraceFormatter();
formatter.setShowOutBody(true);
formatter.setShowOutBodyType(true);
// set to use our formatter
tracer.setFormatter(formatter);
context.addInterceptStrategy(tracer);
context.addRoutes(new RouteBuilder() {
public void configure() {
try {
DataFormat bindy = new BindyCsvDataFormat(com.dto.EmployeeDTO.class);
from("file://TEST?fileName=Employee.csv").
unmarshal(bindy).
marshal().
xstream().
to("file://TESTOUT?fileName=EmployeeXML.xml");
/*DataFormat bindy = new BindyCsvDataFormat(com.dto.EmployeeDTO.class);
from("F://Employee.csv").
unmarshal(bindy).
marshal().
xstream().
to("F://EmployeeXML.xml");*/
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void main(String[] args) {
try{
CamelContext context = new DefaultCamelContext();
ConverterRoute route = new ConverterRoute();
System.out.println("Starting........");
route.addRoutesToCamelContext(context);
context.start();
Thread.sleep(5000);
System.out.println("Ending........");
context.stop();
}catch(Exception exe){
exe.printStackTrace();
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@CsvRecord(separator = ",", skipFirstLine = true)
public class EmployeeDTO implements Serializable{
@XmlAttribute
@DataField(pos = 1)
private int employeeId;
@XmlAttribute
@DataField(pos = 2)
private String firstName;
@XmlAttribute
@DataField(pos = 3)
private String lastName;
@XmlAttribute
@DataField(pos = 4)
private String role;
}
を作成されていない:apacheのラクダを使用してXMLファイルにCSVファイルを変換:XMLファイルは、私は次のエラーを取得しています
Starting........
log4j:WARN No appenders could be found for logger (org.apache.camel.impl.DefaultCamelContext). log4j:WARN Please initialize the log4j system properly.
Ending........
変換後のXMLは、所望のフォルダに生成されていません。