From e14be27fcc4e43cc597ddb79bce2ce7aab8e0288 Mon Sep 17 00:00:00 2001 From: ypatil Date: Thu, 4 Feb 2016 14:10:46 +0530 Subject: [PATCH] Spring with Apache Camel for file processing --- spring-apache-camel/data/file1.txt | 1 + .../data/input/.camel/file1.txt | 1 + .../data/outputLowerCase/file1.txt | 1 + .../data/outputUppperCase/file1.txt | 1 + spring-apache-camel/pom.xml | 43 +++++++++++++++++++ .../main/java/org/apache/camel/main/App.java | 12 ++++++ .../apache/camel/processor/FileProcessor.java | 19 ++++++++ .../src/main/resources/camel-context.xml | 41 ++++++++++++++++++ 8 files changed, 119 insertions(+) create mode 100644 spring-apache-camel/data/file1.txt create mode 100644 spring-apache-camel/data/input/.camel/file1.txt create mode 100644 spring-apache-camel/data/outputLowerCase/file1.txt create mode 100644 spring-apache-camel/data/outputUppperCase/file1.txt create mode 100644 spring-apache-camel/pom.xml create mode 100644 spring-apache-camel/src/main/java/org/apache/camel/main/App.java create mode 100644 spring-apache-camel/src/main/java/org/apache/camel/processor/FileProcessor.java create mode 100644 spring-apache-camel/src/main/resources/camel-context.xml diff --git a/spring-apache-camel/data/file1.txt b/spring-apache-camel/data/file1.txt new file mode 100644 index 0000000000..c8436b654b --- /dev/null +++ b/spring-apache-camel/data/file1.txt @@ -0,0 +1 @@ +THIS IS UPPERCASE CONTENT. this is lowecase content. \ No newline at end of file diff --git a/spring-apache-camel/data/input/.camel/file1.txt b/spring-apache-camel/data/input/.camel/file1.txt new file mode 100644 index 0000000000..c8436b654b --- /dev/null +++ b/spring-apache-camel/data/input/.camel/file1.txt @@ -0,0 +1 @@ +THIS IS UPPERCASE CONTENT. this is lowecase content. \ No newline at end of file diff --git a/spring-apache-camel/data/outputLowerCase/file1.txt b/spring-apache-camel/data/outputLowerCase/file1.txt new file mode 100644 index 0000000000..06a9866342 --- /dev/null +++ b/spring-apache-camel/data/outputLowerCase/file1.txt @@ -0,0 +1 @@ +this is uppercase content. this is lowecase content. \ No newline at end of file diff --git a/spring-apache-camel/data/outputUppperCase/file1.txt b/spring-apache-camel/data/outputUppperCase/file1.txt new file mode 100644 index 0000000000..ce07e477bc --- /dev/null +++ b/spring-apache-camel/data/outputUppperCase/file1.txt @@ -0,0 +1 @@ +THIS IS UPPERCASE CONTENT. THIS IS LOWECASE CONTENT. \ No newline at end of file diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml new file mode 100644 index 0000000000..5b143fedb4 --- /dev/null +++ b/spring-apache-camel/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + org.apache.camel + spring-apache-camel + jar + 1.0-SNAPSHOT + spring-apache-camel + http://maven.apache.org + + + 2.16.1 + 4.2.4.RELEASE + + + + + + org.apache.camel + camel-core + ${env.camel.version} + + + + org.apache.camel + camel-spring + ${env.camel.version} + + + + org.apache.camel + camel-stream + ${env.camel.version} + + + + org.springframework + spring-context + ${env.spring.version} + + + + diff --git a/spring-apache-camel/src/main/java/org/apache/camel/main/App.java b/spring-apache-camel/src/main/java/org/apache/camel/main/App.java new file mode 100644 index 0000000000..4d0793903e --- /dev/null +++ b/spring-apache-camel/src/main/java/org/apache/camel/main/App.java @@ -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(); + } +} \ No newline at end of file diff --git a/spring-apache-camel/src/main/java/org/apache/camel/processor/FileProcessor.java b/spring-apache-camel/src/main/java/org/apache/camel/processor/FileProcessor.java new file mode 100644 index 0000000000..961f877806 --- /dev/null +++ b/spring-apache-camel/src/main/java/org/apache/camel/processor/FileProcessor.java @@ -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); + } + +} diff --git a/spring-apache-camel/src/main/resources/camel-context.xml b/spring-apache-camel/src/main/resources/camel-context.xml new file mode 100644 index 0000000000..d304ceb857 --- /dev/null +++ b/spring-apache-camel/src/main/resources/camel-context.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + ${body.toLowerCase()} + + + + + + + + .......... File content conversion completed .......... + + + + + + + + + \ No newline at end of file