diff --git a/bruno/bruno.json b/bruno/bruno.json new file mode 100644 index 0000000..e4d2338 --- /dev/null +++ b/bruno/bruno.json @@ -0,0 +1,9 @@ +{ + "version": "1", + "name": "camel-springboot-xml-example", + "type": "collection", + "ignore": [ + "node_modules", + ".git" + ] +} \ No newline at end of file diff --git a/bruno/findUsers.bru b/bruno/findUsers.bru new file mode 100644 index 0000000..0889674 --- /dev/null +++ b/bruno/findUsers.bru @@ -0,0 +1,11 @@ +meta { + name: findUsers + type: http + seq: 2 +} + +get { + url: http://localhost:9090/services/api/user + body: none + auth: none +} diff --git a/conf/springboot.yml b/conf/springboot.yml index 2f777d7..d175418 100644 --- a/conf/springboot.yml +++ b/conf/springboot.yml @@ -2,4 +2,7 @@ server: port: 9090 camel: springboot: - main-run-controller: true \ No newline at end of file + main-run-controller: true +spring: + activemq: + broker-url: "tcp://localhost:61616" diff --git a/pom.xml b/pom.xml index 4fdee0d..1cd9ca9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.example - camel-springboot-xml-example - 0.0.2 - camel-springboot-xml-example + camel-springboot-activemq6-example + 1.0.0 + camel-springboot-activemq6-example org.springframework.boot spring-boot-starter-parent - 3.3.2 + 3.3.7 UTF-8 @@ -21,60 +21,67 @@ - - - org.apache.camel.springboot - camel-spring-boot-bom - ${camel.version} - pom - import - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - + + + org.apache.camel.springboot + camel-spring-boot-bom + ${camel.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${springboot.version} + pom + import + + + - - org.springframework.boot - spring-boot-starter-web - - - - org.apache.camel.springboot - camel-log-starter - - - org.apache.camel.springboot - camel-bean-starter - - - org.apache.camel.springboot - camel-bean-validator-starter - - - org.apache.camel.springboot - camel-cxf-rest-starter - - - - - com.fasterxml.jackson.jakarta.rs - jackson-jakarta-rs-json-provider - + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.camel.springboot + camel-log-starter + + + org.apache.camel.springboot + camel-bean-starter + + + org.apache.camel.springboot + camel-bean-validator-starter + + + org.apache.camel.springboot + camel-cxf-rest-starter + + + org.apache.camel.springboot + camel-activemq6-starter + + + org.apache.camel.springboot + camel-jackson-starter + + + + com.fasterxml.jackson.jakarta.rs + jackson-jakarta-rs-json-provider + - - - org.apache.cxf - cxf-rt-rs-service-description - ${cxf.version} - + + + org.apache.cxf + cxf-rt-rs-service-description + ${cxf.version} + diff --git a/src/main/java/com/example/camel/Boot.java b/src/main/java/com/example/camel/Boot.java index abbc384..2515f7d 100644 --- a/src/main/java/com/example/camel/Boot.java +++ b/src/main/java/com/example/camel/Boot.java @@ -18,11 +18,12 @@ public class Boot { 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"); } + System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES","*"); SpringApplication.run(Boot.class, args); } diff --git a/src/main/java/com/example/camel/CamelRouter.java b/src/main/java/com/example/camel/CamelRouter.java index 2879196..634f915 100644 --- a/src/main/java/com/example/camel/CamelRouter.java +++ b/src/main/java/com/example/camel/CamelRouter.java @@ -3,7 +3,7 @@ package com.example.camel; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.bean.validator.BeanValidationException; - +import org.apache.camel.model.dataformat.JsonLibrary; import org.springframework.stereotype.Component; import jakarta.ws.rs.core.Response; @@ -11,25 +11,18 @@ import jakarta.ws.rs.core.Response; @Component public class CamelRouter extends RouteBuilder { - @Override - public void configure() throws Exception { - //very raw way, just to handle the validation responses - onException(BeanValidationException.class) - .handled(true) - .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(Response.Status.BAD_REQUEST.getStatusCode())) - .setBody(simple("${exchangeProperty.CamelExceptionCaught.getMessage()}")); + @Override + public void configure() throws Exception { + // very raw way, just to handle the validation responses + onException(BeanValidationException.class).handled(true) + .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(Response.Status.BAD_REQUEST.getStatusCode())) + .setBody(simple("${exchangeProperty.CamelExceptionCaught.getMessage()}")); - // @formatter:off - from("cxfrs:/api?" + - "resourceClasses="+UserService.class.getName() + - "&bindingStyle=SimpleConsumer" + - "&providers=jaxrsProvider" + - "&loggingFeatureEnabled=true") - .to("bean-validator:user") - .to("log:camel-cxf-log?showAll=true") - .setHeader(Exchange.BEAN_METHOD_NAME, simple("${header.operationName}")) - .bean(UserServiceImpl.class); - // @formatter:on - } + from("cxfrs:/api?resourceClasses=" + UserService.class.getName() + "&bindingStyle=SimpleConsumer" + + "&providers=jaxrsProvider&loggingFeatureEnabled=true").to("bean-validator:user") + .setHeader(Exchange.BEAN_METHOD_NAME, simple("${header.operationName}")).to("activemq6:queue:UserService"); + from("activemq6:queue:UserService").to("log:camel-cxf-log?showAll=true").bean(UserServiceImpl.class).marshal() + .json(JsonLibrary.Jackson); + } } \ No newline at end of file