Spring with Apache Camel for file processing
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
41
spring-apache-camel/src/main/resources/camel-context.xml
Normal file
41
spring-apache-camel/src/main/resources/camel-context.xml
Normal 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>
|
||||
Reference in New Issue
Block a user