1
votes

I am using Apache camel and spring boot for one application. I need to read from a directory and then unmarshal the xml read and then process the unmarshalled object to set some more data in it and then to marshal it again and to send it to a different folder. I am using the following route. Please tell me how to send the POJO after unmarshalling to the processor. Presently it is by default the exchange going into the processor.

@SpringBootApplication
public class CamelApplication extends FatJarRouter {

    public static void main(String ... args) {
        SpringApplication.run(CamelApplication.class, args);
    }

    @Override
    public void configure() throws Exception {
        from("file:input?noop=true")
        .log("Read from the input file")
        .unmarshal(new XMLtoPOJO())
        .log("Unmarshalled the xml")
        .process(new MyProcessortoSetMoreDatatoPOJO())
        .log("Enriched with more data in processor")
        .to("file:destination")
        .log("Written to output file");
    }
}
1

1 Answers

1
votes

If you are using the processor, you can get the pojo from the exchange as follows:

MyPojo pojo = exchange.getIn().getBody(MyPojo.class);

Instead of processor you can just write a plain POJO bean with the method signature of the POJO bean to use

 public void doSomething(MyPojo pojo)

And then call that bean from Camel. See more details at: http://camel.apache.org/bean