Clean up Apache Camel example
This commit is contained in:
parent
9d6f56c40a
commit
54a1235d17
|
@ -23,6 +23,6 @@ To build this application execute following maven command in ApacheCamelFileProc
|
||||||
|
|
||||||
<code>mvn clean install</code>
|
<code>mvn clean install</code>
|
||||||
|
|
||||||
To run this application you can either run our main class org.apache.camel.main.App from your IDE or you can execute following maven command:
|
To run this application you can either run our main class App from your IDE or you can execute following maven command:
|
||||||
|
|
||||||
<code>mvn exec:java -Dexec.mainClass="org.apache.camel.main.App"</code>
|
<code>mvn exec:java -Dexec.mainClass="App"</code>
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.camel.main;
|
package com.baeldung.camel.main;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.baeldung.camel.processor;
|
||||||
|
|
||||||
|
import org.apache.camel.Exchange;
|
||||||
|
import org.apache.camel.Processor;
|
||||||
|
|
||||||
|
public class FileProcessor implements Processor {
|
||||||
|
|
||||||
|
public void process(Exchange exchange) throws Exception {
|
||||||
|
String originalFileContent = exchange.getIn().getBody(String.class);
|
||||||
|
String upperCaseFileContent = originalFileContent.toUpperCase();
|
||||||
|
exchange.getIn().setBody(upperCaseFileContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
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 {
|
|
||||||
String originalFileContent = exchange.getIn().getBody(String.class);
|
|
||||||
String upperCaseFileContent = originalFileContent.toUpperCase();
|
|
||||||
exchange.getIn().setBody(upperCaseFileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -27,8 +27,7 @@
|
||||||
|
|
||||||
<!-- Display process completion message on console -->
|
<!-- Display process completion message on console -->
|
||||||
<transform>
|
<transform>
|
||||||
<simple> .......... File content conversion completed ..........
|
<simple>.......... File content conversion completed ..........</simple>
|
||||||
</simple>
|
|
||||||
</transform>
|
</transform>
|
||||||
<to uri="stream:out"/>
|
<to uri="stream:out"/>
|
||||||
|
|
||||||
|
@ -36,5 +35,5 @@
|
||||||
|
|
||||||
</camelContext>
|
</camelContext>
|
||||||
|
|
||||||
<bean id="myFileProcessor" class="org.apache.camel.processor.FileProcessor" />
|
<bean id="myFileProcessor" class="com.baeldung.camel.processor.FileProcessor"/>
|
||||||
</beans>
|
</beans>
|
|
@ -1 +1 @@
|
||||||
THIS IS UPPERCASE CONTENT. this is lowercase content.
|
This is data that will be processed by a Camel route!
|
|
@ -1,5 +1,12 @@
|
||||||
package org.apache.camel.main;
|
package org.apache.camel.main;
|
||||||
|
|
||||||
|
import com.baeldung.camel.main.App;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.camel.util.FileUtil;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -8,19 +15,12 @@ import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.camel.util.FileUtil;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class AppTest extends TestCase {
|
public class AppTest extends TestCase {
|
||||||
|
|
||||||
private static final String FILE_NAME = "file.txt";
|
private static final String FILE_NAME = "file.txt";
|
||||||
private static final String SAMPLE_INPUT_DIR = "src/test/data/sampleInputFile/";
|
private static final String SAMPLE_INPUT_DIR = "src/test/data/sampleInputFile/";
|
||||||
private static final String TEST_INPUT_DIR = "src/test/data/input/";
|
private static final String TEST_INPUT_DIR = "src/test/data/input/";
|
||||||
private static final String UPPERCARE_OUTPUT_DIR = "src/test/data/outputUpperCase/";
|
private static final String UPPERCASE_OUTPUT_DIR = "src/test/data/outputUpperCase/";
|
||||||
private static final String LOWERCASE_OUTPUT_DIR = "src/test/data/outputLowerCase/";
|
private static final String LOWERCASE_OUTPUT_DIR = "src/test/data/outputLowerCase/";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -34,7 +34,7 @@ public class AppTest extends TestCase {
|
||||||
System.out.println("Deleting the test input and output files...");
|
System.out.println("Deleting the test input and output files...");
|
||||||
deleteFile(TEST_INPUT_DIR);
|
deleteFile(TEST_INPUT_DIR);
|
||||||
deleteFile(LOWERCASE_OUTPUT_DIR);
|
deleteFile(LOWERCASE_OUTPUT_DIR);
|
||||||
deleteFile(UPPERCARE_OUTPUT_DIR);
|
deleteFile(UPPERCASE_OUTPUT_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -42,7 +42,7 @@ public class AppTest extends TestCase {
|
||||||
App.main(null);
|
App.main(null);
|
||||||
|
|
||||||
String inputFileContent = readFileContent(SAMPLE_INPUT_DIR + FILE_NAME);
|
String inputFileContent = readFileContent(SAMPLE_INPUT_DIR + FILE_NAME);
|
||||||
String outputUpperCase = readFileContent(UPPERCARE_OUTPUT_DIR+FILE_NAME);
|
String outputUpperCase = readFileContent(UPPERCASE_OUTPUT_DIR + FILE_NAME);
|
||||||
String outputLowerCase = readFileContent(LOWERCASE_OUTPUT_DIR + FILE_NAME);
|
String outputLowerCase = readFileContent(LOWERCASE_OUTPUT_DIR + FILE_NAME);
|
||||||
|
|
||||||
System.out.println("Input File content = [" + inputFileContent + "]");
|
System.out.println("Input File content = [" + inputFileContent + "]");
|
||||||
|
|
Loading…
Reference in New Issue