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 <noreplay@yahoo.com>
This commit is contained in:
@@ -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,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
package com.baeldung.camel.file;
|
||||
package com.baeldung.camel.apache.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
@@ -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,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,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.baeldung.camel.apache.jackson;
|
||||
|
||||
public class Fruit {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.baeldung.camel.apache.jackson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.main;
|
||||
package com.baeldung.camel.apache.main;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -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;
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionThrowingRoute extends RouteBuilder {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionThrowingRoute.class);
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-exception")
|
||||
.routeId("exception-throwing-route")
|
||||
.process(new Processor() {
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
LOGGER.error("Exception Thrown");
|
||||
throw new IllegalArgumentException("An exception happened on purpose");
|
||||
|
||||
}
|
||||
}).to("mock:received");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.camel.boot.exception;
|
||||
|
||||
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 IllegalArgumentExceptionThrowingProcessor implements Processor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionLoggingProcessor.class);
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
LOGGER.error("Exception Thrown");
|
||||
throw new IllegalArgumentException("An exception happened on purpose");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
logging.config=classpath:logback.xml
|
||||
|
||||
# the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here
|
||||
camel.springboot.name=MyCamel
|
||||
|
||||
# lets listen on all ports to ensure we can be invoked from the pod IP
|
||||
server.address=0.0.0.0
|
||||
management.address=0.0.0.0
|
||||
|
||||
# lets use a different management port in case you need to listen to HTTP requests on 8080
|
||||
management.port=8081
|
||||
|
||||
# disable all management enpoints except health
|
||||
endpoints.enabled = true
|
||||
endpoints.health.enabled = true
|
||||
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
@@ -0,0 +1,27 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
# for example purposes of Camel version 2.18 and below
|
||||
baeldung:
|
||||
api:
|
||||
path: '/camel'
|
||||
|
||||
camel:
|
||||
springboot:
|
||||
# The Camel context name
|
||||
name: ServicesRest
|
||||
|
||||
# Binding health checks to a different port
|
||||
management:
|
||||
port: 8081
|
||||
|
||||
# disable all management enpoints except health
|
||||
endpoints:
|
||||
enabled: false
|
||||
health:
|
||||
enabled: true
|
||||
|
||||
# The application configuration properties
|
||||
quickstart:
|
||||
generateOrderPeriod: 10s
|
||||
processOrderPeriod: 30s
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="contentBasedFileRouter" class="com.baeldung.camel.file.ContentBasedFileRouter" />
|
||||
<bean id="contentBasedFileRouter" class="com.baeldung.camel.apache.file.ContentBasedFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="contentBasedFileRouter" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="deadLetterChannelFileRouter" class="com.baeldung.camel.file.DeadLetterChannelFileRouter" />
|
||||
<bean id="deadLetterChannelFileRouter" class="com.baeldung.camel.apache.file.DeadLetterChannelFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="deadLetterChannelFileRouter" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="messageTranslatorFileRouter" class="com.baeldung.camel.file.MessageTranslatorFileRouter" />
|
||||
<bean id="messageTranslatorFileRouter" class="com.baeldung.camel.apache.file.MessageTranslatorFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="messageTranslatorFileRouter" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="multicastFileRouter" class="com.baeldung.camel.file.MulticastFileRouter" />
|
||||
<bean id="multicastFileRouter" class="com.baeldung.camel.apache.file.MulticastFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="multicastFileRouter" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="splitterFileRouter" class="com.baeldung.camel.file.SplitterFileRouter" />
|
||||
<bean id="splitterFileRouter" class="com.baeldung.camel.apache.file.SplitterFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="splitterFileRouter" />
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="fileRouter" class="com.baeldung.camel.file.FileRouter" />
|
||||
<bean id="fileProcessor" class="com.baeldung.camel.file.FileProcessor" />
|
||||
<bean id="fileRouter" class="com.baeldung.camel.apache.file.FileRouter" />
|
||||
<bean id="fileProcessor" class="com.baeldung.camel.apache.file.FileProcessor" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="fileRouter" />
|
||||
|
||||
@@ -35,5 +35,5 @@
|
||||
|
||||
</camelContext>
|
||||
|
||||
<bean id="myFileProcessor" class="com.baeldung.camel.processor.FileProcessor" />
|
||||
<bean id="myFileProcessor" class="com.baeldung.camel.apache.processor.FileProcessor" />
|
||||
</beans>
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.baeldung;
|
||||
package com.apache.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.camel.main.App;
|
||||
import com.baeldung.camel.apache.main.App;
|
||||
|
||||
public class SpringContextTest {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.apache.baeldung.camel.jackson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -13,6 +13,8 @@ import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.camel.apache.jackson.Fruit;
|
||||
|
||||
public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||
|
||||
@Test
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
package com.apache.baeldung.camel.jackson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -13,6 +13,9 @@ import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.camel.apache.jackson.Fruit;
|
||||
import com.baeldung.camel.apache.jackson.FruitList;
|
||||
|
||||
public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||
|
||||
@Test
|
||||
@@ -11,7 +11,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.baeldung.camel.file.cfg.ContentBasedFileRouterConfig;
|
||||
import com.baeldung.camel.apache.file.cfg.ContentBasedFileRouterConfig;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ContentBasedFileRouterIntegrationTest {
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.baeldung.camel.file.FileProcessor;
|
||||
import com.baeldung.camel.apache.file.FileProcessor;
|
||||
|
||||
|
||||
public class FileProcessorIntegrationTest {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.apache.camel.main;
|
||||
|
||||
import com.baeldung.camel.main.App;
|
||||
import com.baeldung.camel.apache.main.App;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.camel.util.FileUtil;
|
||||
import org.junit.After;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.boot;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.boot.camel.boot.testing;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.apache.camel.test.spring.junit5.MockEndpoints;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@MockEndpoints("file:output")
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class GreetingsFileRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:file:output")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedBodiesReceived("Hello Baeldung Readers!");
|
||||
|
||||
template.sendBody("direct:start", null);
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.boot.camel.conditional;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ConditionalBeanRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendBodyWithFruit_thenFavouriteHeaderReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedHeaderReceived("favourite", "Apples");
|
||||
|
||||
template.sendBodyAndHeader("direct:start-conditional-bean", null, "fruit", "Apple");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.boot.camel.conditional;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ConditionalBodyRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result-body")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendBodyWithBaeldung_thenGoodbyeMessageReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedBodiesReceived("Goodbye, Baeldung!");
|
||||
|
||||
template.sendBody("direct:start-conditional", "Hello Baeldung Readers!");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.boot.camel.conditional;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ConditionalHeaderRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendBodyWithFruit_thenFavouriteHeaderReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedHeaderReceived("favourite", "Banana");
|
||||
|
||||
template.sendBodyAndHeader("direct:start-conditional-header", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.boot.camel.exception;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ExceptionHandlingWithDoTryRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:caught")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendHeaders_thenExceptionRaisedAndHandledSuccessfully() throws Exception {
|
||||
mock.expectedMessageCount(1);
|
||||
|
||||
template.sendBodyAndHeader("direct:start-handling-exception", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.boot.camel.exception;
|
||||
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ExceptionHandlingWithExceptionClauseRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:handled")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendHeaders_thenExceptionRaisedAndHandledSuccessfully() throws Exception {
|
||||
mock.expectedMessageCount(1);
|
||||
|
||||
template.sendBodyAndHeader("direct:start-exception-clause", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.boot.camel.exception;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.ExchangePattern;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.baeldung.camel.boot.Application;
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@CamelSpringBootTest
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
class ExceptionThrowingRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void whenSendBody_thenExceptionRaisedSuccessfully() {
|
||||
CamelContext context = template.getCamelContext();
|
||||
Exchange exchange = context.getEndpoint("direct:start-exception")
|
||||
.createExchange(ExchangePattern.InOut);
|
||||
|
||||
exchange.getIn().setBody("Hello Baeldung");
|
||||
Exchange out = template.send("direct:start-exception", exchange);
|
||||
|
||||
assertTrue(out.isFailed(), "Should be failed");
|
||||
assertTrue(out.getException() instanceof IllegalArgumentException, "Should be IllegalArgumentException");
|
||||
assertEquals("An exception happened on purpose", out.getException().getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.boot.camel.exception;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.baeldung.camel.boot.exception.IllegalArgumentExceptionThrowingProcessor;
|
||||
|
||||
class IllegalArgumentExceptionThrowingProcessorUnitTest {
|
||||
|
||||
@Test
|
||||
void whenProcessed_thenIllegalArgumentExceptionRaisedSuccessfully() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new IllegalArgumentExceptionThrowingProcessor().process(null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user