Spring with Apache Camel for file processing
This commit is contained in:
parent
9de8a4a436
commit
e14be27fcc
|
@ -0,0 +1 @@
|
|||
THIS IS UPPERCASE CONTENT. this is lowecase content.
|
|
@ -0,0 +1 @@
|
|||
THIS IS UPPERCASE CONTENT. this is lowecase content.
|
|
@ -0,0 +1 @@
|
|||
this is uppercase content. this is lowecase content.
|
|
@ -0,0 +1 @@
|
|||
THIS IS UPPERCASE CONTENT. THIS IS LOWECASE CONTENT.
|
|
@ -0,0 +1,43 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>spring-apache-camel</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>spring-apache-camel</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<env.camel.version>2.16.1</env.camel.version>
|
||||
<env.spring.version>4.2.4.RELEASE</env.spring.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-core</artifactId>
|
||||
<version>${env.camel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-spring</artifactId>
|
||||
<version>${env.camel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-stream</artifactId>
|
||||
<version>${env.camel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${env.spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
Loading…
Reference in New Issue