Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiwaehner committed Feb 21, 2012
1 parent b39c1bd commit f76d60e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
14 changes: 9 additions & 5 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
Camel Introduction Project
==========================
Apache Camel Introduction Project
=================================

This is an Eclipse project. Nevertheless, it can be used via console, or imported into NetBeans / IntelliJ IDEA.

Libraries are imported via Maven to ease dependecy management.
Libraries are imported via Maven to ease dependency management.
You should always use the newest version of Camel before starting (current version: 2.9.0).

Run the UnitTest (IntegrationTest.java). Put a breakpoint into the debugger and start playing around.
You can also start the main method of CamelStarter.java and copy the real_order.csv file to the inbox directory
If you do not understand the message flow, uncomment ".tracing()" in the route to get more detailed information.
You can also start the main method of CamelStarter.java and copy the resources/real_order.csv file to the inbox directory
(within 30 seconds) to see how it is processed.

This is only a very simple example for getting started. In practice, you would have to do some stuff differently, of course.
For instance: If you have got two dvd orders, the last one overrides the first one in the outbox/dvd folder at the moment.

Have fun with Apache Camel.

Best regards,
Kai W�hner
Kai Waehner
Twitter: @KaiWaehner
www.kai-waehner.de

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/infoq/camel/IntegrationRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@ public class IntegrationRoute extends RouteBuilder {
public void configure() throws Exception {

// Consumer Endpoint
from("file:orders/inbox")
from("file:orders/inbox?noop=true")
// if tracing is turned on, you get very detailed information about processing within the route.
.tracing()
//.tracing()
// a processor does custom integration logic
.process(new LoggingProcessor())
// a bean also does custom integration logic
.bean(new TransformationBean(), "makeUpperCase")
// Translator EIP (using the camel-csv component)
.unmarshal().csv()
// Splitter EIP
.split().body()
.split(body().tokenize(","))
// Content-based Router EIP
.log("Kai: ${body}")
.choice()
.when(body().contains("DVD"))
// Producer Endpoint
.to("file:orders/outbox/dvd")
.when(body().contains("CD"))
.to("file:orders/outbox/cd")
.otherwise()
.to("file:orders/mock");

.to("mock:others");
}

}
2 changes: 1 addition & 1 deletion src/main/resources/real_order.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Xzibit - Hood / cd
Xzibit - Hood / cd,event horizon / dvd,the bible / book,Metallica / cd
16 changes: 9 additions & 7 deletions src/test/java/infoq/camel/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@ public void setup() throws Exception {
@Test
public void testFileToFile() throws Exception {

// Body contains one CD, one DVD and one BOOK.
String bodyOfMessage = "harry potter and the deathly hollows / dvd, "
+ "dj Food - kaleidoscope / cd, " + "Xzibit - hood / cd, "
+ "Claus Ibsen - Camel in Action / book";
// Body contains two CDs, one DVD and one BOOK.
String bodyOfMessage =
"eminem / cd,harry potter and the deathly hollows / dvd,"
+ "Claus Ibsen - Camel in Action / book,"
+ "Xzibit / cd";

// The TemplateProducer is part of CamelTestSupport. It is used to send messages to Camel endpoints.
template.sendBodyAndHeader("file://orders/inbox", bodyOfMessage, Exchange.FILE_NAME, "order.csv");

// Mock is included implicitly.
MockEndpoint mock = context.getEndpoint("mock:others", MockEndpoint.class);
// The Mock expects only one message, because it only receives the BOOK order.
// The Mock expects only one message, because it only receives the BOOK order:
mock.expectedMessageCount(1);
mock.setResultWaitTime(1000);

Thread.sleep(3000);

String dvdBody = "harry potter and the deathly hollows / dvd";
String dvdBody = " harry potter and the deathly hollows / dvd";

File target = new File("orders/outbox/dvd/order.csv");
String content = context.getTypeConverter().convertTo(String.class, target);

// Assertions
assertEquals(dvdBody.toUpperCase(), content);
mock.assertIsSatisfied();
assertEquals(dvdBody.toUpperCase(), content);



}
Expand Down

0 comments on commit f76d60e

Please sign in to comment.