Thursday, December 8, 2016

Apache Camel and YAML processing example

I had trouble finding a full example of how to process YAML files using Apache Camel. So here's an example I've written:


         from("file:/home/philip/ga4gh_registration?move=archived")  
           .choice()  
             .when(header("CamelFileName").endsWith(".yml"))  
               .unmarshal()  
               .yaml(YAMLLibrary.SnakeYAML)  
               .process(new Processor() {  
                 @Override  
                 void process(Exchange exchange) throws Exception {  
                   String filename = exchange.getIn().getHeader("CamelFileName")  
                   logger.info("registerDataset: "+filename)  
                   def yamlObj = exchange.getIn().body  
                   logger.info("body="+yamlObj)  
                   logger.info("datasetName="+yamlObj.datasetName)  
                 }  
               })  
             .otherwise()  
               .log("Bad registration file: "+header("CamelFileName"))  
           .end()  

References:


http://camel.apache.org/yaml-data-format.html

No comments:

Post a Comment