commit 58de3d3b148d1ae74debd96ee7319b3b2a9f66dc Author: Ng Yat Yan Date: Sun Sep 8 21:30:44 2024 +0800 V0.0.1 Simple Spring-boot Server Defined by Camel XML Routing diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8801278 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +/.classpath +/.project +/.settings \ No newline at end of file diff --git a/conf/logback.xml b/conf/logback.xml new file mode 100644 index 0000000..8ddf4a7 --- /dev/null +++ b/conf/logback.xml @@ -0,0 +1,26 @@ + + + + + %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n + + + + logs/server.log + + logs/server.%d{yyyy-MM-dd}.log.gz + 3 + 300MB + + + %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/conf/springboot.yml b/conf/springboot.yml new file mode 100644 index 0000000..74be0c2 --- /dev/null +++ b/conf/springboot.yml @@ -0,0 +1,2 @@ +server: + port: 9090 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5d07e63 --- /dev/null +++ b/pom.xml @@ -0,0 +1,92 @@ + + 4.0.0 + com.example + camel-springboot-xml-example + 0.0.1 + camel-springboot-xml-example + + org.springframework.boot + spring-boot-starter-parent + 3.3.2 + + + UTF-8 + 4.7.0 + ${project.parent.version} + + + + + + org.apache.camel.springboot + camel-spring-boot-bom + ${camel.version} + pom + import + + + org.apache.camel + camel-bom + ${camel.version} + pom + import + + + + + + org.apache.camel.springboot + camel-spring-boot-xml-starter + + + org.apache.camel + camel-jsonpath + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + + + ch.qos.logback + logback-core + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + org.springframework.boot + spring-boot-maven-plugin + + com.example.camel.Boot + + + + build-info + + build-info + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/example/camel/Boot.java b/src/main/java/com/example/camel/Boot.java new file mode 100644 index 0000000..8323eed --- /dev/null +++ b/src/main/java/com/example/camel/Boot.java @@ -0,0 +1,31 @@ +package com.example.camel; + +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource("classpath:camel-route.xml") +public class Boot { + + private static final Logger logger = LoggerFactory.getLogger(Boot.class); + + public static void main(String[] args) { + String configDirectory = "conf"; + if (args.length > 0) { + configDirectory = args[0]; + } + logger.info("config directory: {}", configDirectory); + + if (new File(configDirectory).exists() && new File(configDirectory).isDirectory()) { + System.setProperty("spring.config.location", configDirectory + "/springboot.yml"); + System.setProperty("logging.config", configDirectory + "/logback.xml"); + } + SpringApplication.run(Boot.class, args); + } + +} diff --git a/src/main/resources/camel-route.xml b/src/main/resources/camel-route.xml new file mode 100644 index 0000000..ef6b558 --- /dev/null +++ b/src/main/resources/camel-route.xml @@ -0,0 +1,90 @@ + + + + + + + + + + ${headers.CamelHttpMethod} == 'POST' + + $.notification.type + + + + ${header.type} == 'email' + + + + 200 + + + + ${header.type} == 'http' + + + + 200 + + + + + + { "status": "reject", "type": "unknown" } + + + 400 + + + + + + + + { "error": "only POST is accepted" } + + + 500 + + + + + + + + + $.notification.to + + + Notification + + + $.notification.message + + + + { "status": "email sent", "to": "${header.to}", "subject": + "${header.subject}" } + + + + + + + $.notification.service + + + + { "status": "http requested", "service": "${header.service}" + } + + + + \ No newline at end of file