Spring with Apache Camel for file processing

This commit is contained in:
ypatil
2016-02-04 14:10:46 +05:30
parent 9de8a4a436
commit e14be27fcc
8 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package org.apache.camel.main;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(final String[] args) throws Exception {
//Load application context
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context.xml");
Thread.sleep(5000);
applicationContext.close();
}
}

View File

@@ -0,0 +1,19 @@
package org.apache.camel.processor;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class FileProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
//Read file content
String originalFileContent = (String)exchange.getIn().getBody(String.class);
//Convert file content to upper case.
String upperCaseFileContent = originalFileContent.toUpperCase();
//Update file content.
exchange.getIn().setBody(upperCaseFileContent);
}
}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route customId="true" id="rout1">
<!-- Read files from input directory -->
<from uri="file://data/input" />
<!-- Transform content to UpperCase -->
<process ref="myFileProcessor" />
<!-- Write converted file content -->
<to uri="file://data/outputUppperCase" />
<!-- Transform content to LowerCase -->
<transform>
<simple>${body.toLowerCase()}</simple>
</transform>
<!-- Write converted file content -->
<to uri="file://data/outputLowerCase" />
<!-- Display process completion message on console -->
<transform>
<simple> .......... File content conversion completed ..........</simple>
</transform>
<to uri="stream:out" />
</route>
</camelContext>
<bean id="myFileProcessor" class="org.apache.camel.processor.FileProcessor" />
</beans>