Skip to content

Commit b290c14

Browse files
author
SKP
committed
Apache Camel+SpringBoot REST API Example
Apache Camel+SpringBoot REST API Example
1 parent eaaecbc commit b290c14

5 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.javaoutofbounds</groupId>
7+
<artifactId>springboot-camel-restdsl-api</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>springboot-camel-restdsl-api</name>
12+
<description>Camel SpringBoot REST API Example with REST DSL</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.9.RELEASE</version>
18+
<relativePath /> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.apache.camel</groupId>
34+
<artifactId>camel-spring-boot-starter</artifactId>
35+
<version>2.19.0</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.apache.camel</groupId>
39+
<artifactId>camel-servlet-starter</artifactId>
40+
<version>2.19.0</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.camel</groupId>
44+
<artifactId>camel-jackson</artifactId>
45+
<version>2.19.0</version>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.javaoutofbounds.pojo;
2+
3+
import java.util.concurrent.atomic.AtomicLong;
4+
5+
import org.apache.camel.Exchange;
6+
import org.apache.camel.Processor;
7+
import org.apache.camel.builder.RouteBuilder;
8+
import org.apache.camel.model.rest.RestBindingMode;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.stereotype.Component;
12+
13+
@SpringBootApplication
14+
public class SpringbootCamelRestdslApiApplication {
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(SpringbootCamelRestdslApiApplication.class, args);
18+
}
19+
20+
@Component
21+
class StudentRoute extends RouteBuilder {
22+
23+
@Override
24+
public void configure() {
25+
restConfiguration()
26+
.component("servlet")
27+
.bindingMode(RestBindingMode.json);
28+
29+
rest("/student").produces("application/json")
30+
.get("/hello/{name}")
31+
.route().transform().simple("Hello ${header.name}, Welcome to JavaOutOfBounds.com")
32+
.endRest()
33+
.get("/records/{name}").to("direct:records");
34+
35+
from("direct:records")
36+
.process(new Processor() {
37+
38+
final AtomicLong counter = new AtomicLong();
39+
40+
@Override
41+
public void process(Exchange exchange) throws Exception {
42+
43+
final String name = exchange.getIn().getHeader("name",String.class);
44+
exchange.getIn().setBody(new Student(counter.incrementAndGet(),name,"Camel + SpringBoot"));
45+
}
46+
});
47+
}
48+
}
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.javaoutofbounds.pojo;
2+
3+
public class Student {
4+
5+
private long id;
6+
private String name;
7+
private String subject;
8+
9+
public Student(long id,String name, String subject) {
10+
this.id = id;
11+
this.name = name;
12+
this.subject = subject;
13+
}
14+
15+
public long getId() {
16+
return id;
17+
}
18+
19+
public void setId(long id) {
20+
this.id = id;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public void setName(String name) {
28+
this.name = name;
29+
}
30+
31+
public String getSubject() {
32+
return subject;
33+
}
34+
35+
public void setSubject(String subject) {
36+
this.subject = subject;
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
camel.component.servlet.mapping.context-path=/*

0 commit comments

Comments
 (0)