Skip to content

Commit 0453ba1

Browse files
author
adkm
committed
iluwatar#176 Test run, app shutdown, minor refactoring
1 parent 60f07d1 commit 0453ba1

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/App.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.iluwatar.eip.wiretap;
22

3+
import org.apache.camel.CamelContext;
4+
import org.apache.camel.builder.RouteBuilder;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.ConfigurableApplicationContext;
58

69
/**
710
* In most integration cases there is a need to monitor the messages flowing through the system. It is usually achieved
@@ -22,7 +25,27 @@ public class App {
2225
*
2326
* @param args command line args
2427
*/
25-
public static void main(String[] args) {
26-
SpringApplication.run(App.class, args);
28+
public static void main(String[] args) throws Exception{
29+
// Run Spring Boot application and obtain ApplicationContext
30+
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
31+
32+
// Get CamelContext from ApplicationContext
33+
CamelContext camelContext = (CamelContext) context.getBean("camelContext");
34+
35+
// Add a new routes that will handle endpoints form WireTapRoute class.
36+
camelContext.addRoutes(new RouteBuilder() {
37+
38+
@Override
39+
public void configure() throws Exception {
40+
from("{{endpoint}}").log("ENDPOINT: ${body}");
41+
from("{{wireTapEndpoint}}").log("WIRETAPPED ENDPOINT: ${body}");
42+
}
43+
44+
});
45+
46+
// Add producer that will send test message to an entry point in WireTapRoute
47+
camelContext.createProducerTemplate().sendBody("{{entry}}", "Test message");
48+
49+
SpringApplication.exit(context);
2750
}
2851
}

eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/routes/WireTapRoute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public void configure() throws Exception {
2727
from("{{entry}}").wireTap("direct:wireTap").to("{{endpoint}}");
2828

2929
// Wire tap route
30-
from("direct:wireTap").to("{{wireTapEndpoint}}");
30+
from("direct:wireTap").log("Message: ${body}").to("{{wireTapEndpoint}}");
3131
}
3232
}

eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class AppTest {
99

1010
@Test
11-
public void testMain() {
11+
public void testMain() throws Exception {
1212
String[] args = {};
1313
App.main(args);
1414
}

0 commit comments

Comments
 (0)