JAVA-2420 Merge spring-apache-camel and spring-boot-camel modules (#13409)
* JAVA-2420 Merge spring-apache-camel and spring-boot-camel modules * JAVA-2420 Migrate spring-boot-camel to spring-apache camel * JAVA-2420 Update README.md file * JAVA-2420 Remove spring-boot-camel --------- Co-authored-by: timis1 <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
timis1
parent
09382f545e
commit
a04d35a6d8
@@ -18,7 +18,6 @@
|
||||
<module>jgroups</module>
|
||||
<module>rabbitmq</module>
|
||||
<module>spring-amqp</module>
|
||||
<module>spring-apache-camel</module>
|
||||
<module>spring-jms</module>
|
||||
</modules>
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
/src/test/destination-folder/*
|
||||
/src/test/destination-folder/*
|
||||
/output/
|
||||
@@ -4,17 +4,19 @@ This module contains articles about Spring with Apache Camel
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- [Apache Camel](http://camel.apache.org/)
|
||||
- [Enterprise Integration Patterns](http://www.enterpriseintegrationpatterns.com/patterns/messaging/toc.html)
|
||||
- [Introduction To Apache Camel](http://www.baeldung.com/apache-camel-intro)
|
||||
- [Integration Patterns With Apache Camel](http://www.baeldung.com/camel-integration-patterns)
|
||||
- [Using Apache Camel with Spring](http://www.baeldung.com/spring-apache-camel-tutorial)
|
||||
- [Unmarshalling a JSON Array Using camel-jackson](https://www.baeldung.com/java-camel-jackson-json-array)
|
||||
- [Apache Camel with Spring Boot](https://www.baeldung.com/apache-camel-spring-boot)
|
||||
- [Apache Camel Routes Testing in Spring Boot](https://www.baeldung.com/spring-boot-apache-camel-routes-testing)
|
||||
- [Apache Camel Conditional Routing](https://www.baeldung.com/spring-apache-camel-conditional-routing)
|
||||
- [Apache Camel Exception Handling](https://www.baeldung.com/java-apache-camel-exception-handling)
|
||||
|
||||
### Framework Versions:
|
||||
|
||||
- Spring 4.2.4
|
||||
- Apache Camel 2.16.1
|
||||
- Spring 5.3.25
|
||||
- Apache Camel 3.14.7
|
||||
|
||||
### Build and Run Application
|
||||
|
||||
|
||||
@@ -58,11 +58,67 @@
|
||||
<version>${env.camel.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-servlet-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-jackson-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-swagger-java-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-spring-boot-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-test-spring-junit5</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<env.camel.version>2.18.1</env.camel.version>
|
||||
<env.spring.version>4.3.4.RELEASE</env.spring.version>
|
||||
<env.camel.version>3.14.7</env.camel.version>
|
||||
<env.spring.version>5.3.25</env.spring.version>
|
||||
<camel.version>3.15.0</camel.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>spring-boot</id>
|
||||
<build>
|
||||
<defaultGoal>spring-boot:run</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.camel.boot.boot.testing.GreetingsFileSpringApplication</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.LoggingLevel;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file.cfg;
|
||||
package com.baeldung.camel.apache.file.cfg;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -8,7 +8,7 @@ import org.apache.camel.spring.javaconfig.CamelConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baeldung.camel.file.ContentBasedFileRouter;
|
||||
import com.baeldung.camel.apache.file.ContentBasedFileRouter;
|
||||
|
||||
@Configuration
|
||||
public class ContentBasedFileRouterConfig extends CamelConfiguration {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.baeldung.camel.apache.jackson;
|
||||
|
||||
public class Fruit {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.baeldung.camel.apache.jackson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.main;
|
||||
package com.baeldung.camel.apache.main;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.processor;
|
||||
package com.baeldung.camel.apache.processor;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package com.baeldung.camel.boot;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
|
||||
import org.apache.camel.impl.DefaultCamelContext;
|
||||
import org.apache.camel.model.rest.RestBindingMode;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@SpringBootApplication(exclude = { WebSocketServletAutoConfiguration.class, AopAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class, EmbeddedWebServerFactoryCustomizerAutoConfiguration.class })
|
||||
@ComponentScan(basePackages = "com.baeldung.camel.boot")
|
||||
public class Application {
|
||||
|
||||
@Value("${server.port}")
|
||||
String serverPort;
|
||||
|
||||
@Value("${baeldung.api.path}")
|
||||
String contextPath;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ServletRegistrationBean servletRegistrationBean() {
|
||||
ServletRegistrationBean servlet = new ServletRegistrationBean(new CamelHttpTransportServlet(), contextPath + "/*");
|
||||
servlet.setName("CamelServlet");
|
||||
return servlet;
|
||||
}
|
||||
|
||||
@Component
|
||||
class RestApi extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
|
||||
CamelContext context = new DefaultCamelContext();
|
||||
|
||||
// http://localhost:8080/camel/api-doc
|
||||
restConfiguration().contextPath(contextPath) //
|
||||
.port(serverPort)
|
||||
.enableCORS(true)
|
||||
.apiContextPath("/api-doc")
|
||||
.apiProperty("api.title", "Test REST API")
|
||||
.apiProperty("api.version", "v1")
|
||||
.apiProperty("cors", "true") // cross-site
|
||||
.apiContextRouteId("doc-api")
|
||||
.component("servlet")
|
||||
.bindingMode(RestBindingMode.json)
|
||||
.dataFormatProperty("prettyPrint", "true");
|
||||
/**
|
||||
The Rest DSL supports automatic binding json/xml contents to/from
|
||||
POJOs using Camels Data Format.
|
||||
By default the binding mode is off, meaning there is no automatic
|
||||
binding happening for incoming and outgoing messages.
|
||||
You may want to use binding if you develop POJOs that maps to
|
||||
your REST services request and response types.
|
||||
*/
|
||||
|
||||
rest("/api/").description("Teste REST Service")
|
||||
.id("api-route")
|
||||
.post("/bean")
|
||||
.produces(MediaType.APPLICATION_JSON)
|
||||
.consumes(MediaType.APPLICATION_JSON)
|
||||
// .get("/hello/{place}")
|
||||
.bindingMode(RestBindingMode.auto)
|
||||
.type(MyBean.class)
|
||||
.enableCORS(true)
|
||||
// .outType(OutBean.class)
|
||||
|
||||
.to("direct:remoteService");
|
||||
|
||||
from("direct:remoteService").routeId("direct-route")
|
||||
.tracing()
|
||||
.log(">>> ${body.id}")
|
||||
.log(">>> ${body.name}")
|
||||
// .transform().simple("blue ${in.body.name}")
|
||||
.process(new Processor() {
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
MyBean bodyIn = (MyBean) exchange.getIn()
|
||||
.getBody();
|
||||
|
||||
ExampleServices.example(bodyIn);
|
||||
|
||||
exchange.getIn()
|
||||
.setBody(bodyIn);
|
||||
}
|
||||
})
|
||||
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(201));
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.camel.boot;
|
||||
|
||||
/**
|
||||
* a Mock class to show how some other layer
|
||||
* (a persistence layer, for instance)
|
||||
* could be used insida a Camel
|
||||
*
|
||||
*/
|
||||
public class ExampleServices {
|
||||
|
||||
public static void example(MyBean bodyIn) {
|
||||
bodyIn.setName( "Hello, " + bodyIn.getName() );
|
||||
bodyIn.setId(bodyIn.getId()*10);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.camel.boot;
|
||||
|
||||
public class MyBean {
|
||||
private Integer id;
|
||||
private String name;
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.camel.boot.boot.testing;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class GreetingsFileRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start")
|
||||
.routeId("greetings-route")
|
||||
.setBody(constant("Hello Baeldung Readers!"))
|
||||
.to("file:output");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.camel.boot.boot.testing;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class GreetingsFileSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GreetingsFileSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.camel.boot.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalBeanRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional-bean")
|
||||
.routeId("conditional-bean-route")
|
||||
.choice()
|
||||
.when(method(FruitBean.class, "isApple"))
|
||||
.setHeader("favourite", simple("Apples"))
|
||||
.to("mock:result")
|
||||
.otherwise()
|
||||
.setHeader("favourite", header("fruit"))
|
||||
.to("mock:result")
|
||||
.end();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.camel.boot.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalBodyRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional")
|
||||
.routeId("conditional-body-route")
|
||||
.choice()
|
||||
.when(body().contains("Baeldung"))
|
||||
.setBody(simple("Goodbye, Baeldung!"))
|
||||
.to("mock:result-body")
|
||||
.otherwise()
|
||||
.to("mock:result-body")
|
||||
.end();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.camel.boot.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalHeaderRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional-header")
|
||||
.routeId("conditional-header-route")
|
||||
.choice()
|
||||
.when(header("fruit").isEqualTo("Apple"))
|
||||
.setHeader("favourite", simple("Apples"))
|
||||
.to("mock:result")
|
||||
.otherwise()
|
||||
.setHeader("favourite", header("fruit"))
|
||||
.to("mock:result")
|
||||
.end();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.camel.boot.conditional;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ConditionalRoutingSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConditionalRoutingSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.camel.boot.conditional;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
|
||||
public class FruitBean {
|
||||
|
||||
private FruitBean() {
|
||||
}
|
||||
|
||||
public static boolean isApple(Exchange exchange) {
|
||||
return "Apple".equals(exchange.getIn()
|
||||
.getHeader("fruit"));
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExceptionHandlingSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExceptionHandlingSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionHandlingWithDoTryRoute extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-handling-exception")
|
||||
.routeId("exception-handling-route")
|
||||
.doTry()
|
||||
.process(new IllegalArgumentExceptionThrowingProcessor())
|
||||
.to("mock:received")
|
||||
.doCatch(IOException.class, IllegalArgumentException.class)
|
||||
.to("mock:caught")
|
||||
.doFinally()
|
||||
.to("mock:finally")
|
||||
.end();
|
||||
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionHandlingWithExceptionClauseRoute extends RouteBuilder {
|
||||
|
||||
@Autowired
|
||||
private ExceptionLoggingProcessor exceptionLogger;
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
onException(IllegalArgumentException.class).process(exceptionLogger)
|
||||
.handled(true)
|
||||
.to("mock:handled");
|
||||
|
||||
from("direct:start-exception-clause")
|
||||
.routeId("exception-clause-route")
|
||||
.process(new IllegalArgumentExceptionThrowingProcessor())
|
||||
.to("mock:received");
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionLoggingProcessor implements Processor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionLoggingProcessor.class);
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
Map<String, Object> headersMap = exchange.getIn().getHeaders();
|
||||
|
||||
if (!headersMap.isEmpty()) {
|
||||
headersMap.entrySet()
|
||||
.stream()
|
||||
.forEach(e -> LOGGER.info("Header key [{}] -||- Header value [{}]", e.getKey(), e.getValue()));
|
||||
} else {
|
||||
LOGGER.info("Empty header");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user