Skip to content

Commit f9e4a0a

Browse files
committed
Adding a new sample to show Camel + Java EE integration (starting to work on issue javaee-samples#36)
1 parent 10da618 commit f9e4a0a

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

extra/camel/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee7.extra</groupId>
6+
<artifactId>extra-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<groupId>org.javaee7.extra</groupId>
12+
<artifactId>camel</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
<packaging>war</packaging>
15+
16+
<properties>
17+
<camel.version>2.13.0</camel.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.apache.camel</groupId>
23+
<artifactId>camel-core</artifactId>
24+
<version>${camel.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.camel</groupId>
28+
<artifactId>camel-cdi</artifactId>
29+
<version>${camel.version}</version>
30+
</dependency>
31+
</dependencies>
32+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.javaee7.extra.camel;
2+
3+
import java.util.logging.Level;
4+
import javax.annotation.PostConstruct;
5+
import javax.ejb.Singleton;
6+
import javax.ejb.Startup;
7+
import javax.inject.Inject;
8+
import org.apache.camel.Exchange;
9+
import org.apache.camel.Processor;
10+
import org.apache.camel.builder.RouteBuilder;
11+
import org.apache.camel.cdi.CdiCamelContext;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
/**
16+
* @author Arun Gupta
17+
*/
18+
@Singleton
19+
@Startup
20+
public class Bootstrap {
21+
22+
@Inject
23+
CdiCamelContext context;
24+
25+
Logger logger = LoggerFactory.getLogger(Bootstrap.class);
26+
27+
@PostConstruct
28+
public void init() {
29+
logger.info(">> Create CamelContext and register Camel Route.");
30+
31+
try {
32+
context.addRoutes(new RouteBuilder() {
33+
@Override
34+
public void configure() {
35+
// from("test-jms:queue:test.queue").to("file://test");
36+
from("timer://timer1?period=1000")
37+
.process(new Processor() {
38+
@Override
39+
public void process(Exchange message) throws Exception {
40+
logger.info("Processing {}", message);
41+
}
42+
});
43+
}
44+
});
45+
} catch (Exception ex) {
46+
java.util.logging.Logger.getLogger(Bootstrap.class.getName()).log(Level.SEVERE, null, ex);
47+
}
48+
49+
// Define Timer URI
50+
// simpleRoute.setTimerUri("timer://simple?fixedRate=true&period=10s");
51+
// Start Camel Context
52+
context.start();
53+
54+
logger.info(">> CamelContext created and camel route started.");
55+
}
56+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans
3+
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
6+
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
7+
bean-discovery-mode="all">
8+
</beans>

extra/camel/src/main/webapp/index.jsp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
3+
"http://www.w3.org/TR/html4/loose.dtd">
4+
5+
6+
<html>
7+
<head>
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9+
<title>Apache Camel with Java EE</title>
10+
</head>
11+
<body>
12+
<h1>Apache Camel with Java EE</h1>
13+
Look for messages in server.log.
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)