camel testing
parent
16a308f97e
commit
d2f3e3c683
|
@ -24,9 +24,12 @@ dependencies {
|
||||||
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
|
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
|
||||||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.5.7'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.5.7'
|
||||||
|
|
||||||
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.13.0'
|
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.15.0'
|
||||||
implementation 'org.apache.camel.springboot:camel-http-starter:3.13.0'
|
implementation 'org.apache.camel.springboot:camel-http-starter:3.15.0'
|
||||||
implementation 'org.apache.camel:camel-jackson:3.13.0'
|
implementation 'org.apache.camel:camel-jackson:3.15.0'
|
||||||
|
|
||||||
|
implementation 'org.apache.camel.springboot:camel-rest-starter:3.15.0'
|
||||||
|
implementation 'org.apache.camel:camel-jetty:3.15.0'
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.22'
|
compileOnly 'org.projectlombok:lombok:1.18.22'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package me.bvn13.lesson.camel.testing.cameltesting;
|
package me.bvn13.lesson.camel.testing.cameltesting;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class CamelTestingApplication {
|
public class CamelTestingApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(CamelTestingApplication.class, args);
|
// SpringApplication.run(CamelTestingApplication.class, args);
|
||||||
|
new SpringApplicationBuilder(CamelTestingApplication.class)
|
||||||
|
.web(WebApplicationType.NONE)
|
||||||
|
.run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ import org.springframework.stereotype.Component;
|
||||||
@Profile("!test")
|
@Profile("!test")
|
||||||
public class PropertyProviderImpl implements PropertiesProvider {
|
public class PropertyProviderImpl implements PropertiesProvider {
|
||||||
|
|
||||||
@Value("${app.input.folder}")
|
@Value("${app.input.folder:/tmp/in}")
|
||||||
private String inputFolder;
|
private String inputFolder;
|
||||||
|
|
||||||
@Value("${app.output.folder}")
|
@Value("${app.output.folder:/tmp/out}")
|
||||||
private String outputFolder;
|
private String outputFolder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package me.bvn13.lesson.camel.testing.cameltesting;
|
||||||
|
|
||||||
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
//@Component
|
||||||
|
public class RestRouteBuilder extends RouteBuilder {
|
||||||
|
@Override
|
||||||
|
public void configure() throws Exception {
|
||||||
|
|
||||||
|
restConfiguration()
|
||||||
|
.port(8085)
|
||||||
|
// .host("localhost")
|
||||||
|
;
|
||||||
|
|
||||||
|
rest()
|
||||||
|
.get("/test")
|
||||||
|
.route()
|
||||||
|
.log("${body}")
|
||||||
|
.setBody().body(ex -> "<html><body>OK</body></html>")
|
||||||
|
.end()
|
||||||
|
.endRest()
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,12 +20,9 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static me.bvn13.lesson.camel.testing.cameltesting.SupervisorResponseDto.Verdict.SKIP;
|
|
||||||
|
|
||||||
@Converter
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Component
|
//@Component
|
||||||
public class SimpleRouteBuilder extends RouteBuilder {
|
public class SimpleRouteBuilder extends RouteBuilder {
|
||||||
|
|
||||||
@Value("${app.bad-word}")
|
@Value("${app.bad-word}")
|
||||||
|
@ -54,7 +51,7 @@ public class SimpleRouteBuilder extends RouteBuilder {
|
||||||
.log("processing ${header[CamelFileName]}")
|
.log("processing ${header[CamelFileName]}")
|
||||||
.to("direct://supervisor")
|
.to("direct://supervisor")
|
||||||
.choice()
|
.choice()
|
||||||
.when(exchangeProperty(SUPERVISION_VERDICT).isEqualTo(SKIP))
|
.when(exchangeProperty(SUPERVISION_VERDICT).isEqualTo(SupervisorResponseDto.Verdict.SKIP))
|
||||||
.to("direct://skip")
|
.to("direct://skip")
|
||||||
.otherwise()
|
.otherwise()
|
||||||
.to("direct://process");
|
.to("direct://process");
|
||||||
|
|
|
@ -9,10 +9,10 @@ public class SupervisorResponseDto {
|
||||||
|
|
||||||
Verdict verdict;
|
Verdict verdict;
|
||||||
|
|
||||||
@JsonCreator
|
// @JsonCreator
|
||||||
public SupervisorResponseDto(@JsonProperty("verdict") Verdict verdict) {
|
// public SupervisorResponseDto(@JsonProperty("verdict") Verdict verdict) {
|
||||||
this.verdict = verdict;
|
// this.verdict = verdict;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public enum Verdict {
|
public enum Verdict {
|
||||||
PROCESS,
|
PROCESS,
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package me.bvn13.lesson.camel.testing.cameltesting.danielolivaw;
|
||||||
|
|
||||||
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FileBackupRouteBuilder extends RouteBuilder {
|
||||||
|
|
||||||
|
public static final String SOURCE_FILE_NAME = "SourceFileName";
|
||||||
|
public static final String DESTINATION_FILE_NAME = "DestinationFileName";
|
||||||
|
public static final String DATE_PART_1 = "DATE_PART_1";
|
||||||
|
public static final String DATE_PART_2 = "DATE_PART_2";
|
||||||
|
public static final String DATE_PART_3 = "DATE_PART_3";
|
||||||
|
|
||||||
|
@Value("${source.path}")
|
||||||
|
private String sourcePath;
|
||||||
|
@Value("${destination.path}")
|
||||||
|
private String destinationPath;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure() throws Exception {
|
||||||
|
|
||||||
|
from("file://" + sourcePath + "?delete=false&recursively=true")
|
||||||
|
.routeId("Transfer_Backup")
|
||||||
|
.setProperty(SOURCE_FILE_NAME, header("CamelFileName"))
|
||||||
|
.log("Transferring ${exchangeProperty["+SOURCE_FILE_NAME+"]}")
|
||||||
|
.process(exchange -> {
|
||||||
|
String sourceFileName = exchange.getProperty(SOURCE_FILE_NAME, String.class);
|
||||||
|
// be sure sourceFileName is a name without path
|
||||||
|
String newFileName = sourceFileName + ".bup"; // maybe
|
||||||
|
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
exchange.setProperty(DATE_PART_1, now.getYear());
|
||||||
|
exchange.setProperty(DATE_PART_2, now.getMonthValue());
|
||||||
|
exchange.setProperty(DATE_PART_3, now.getDayOfMonth());
|
||||||
|
exchange.setProperty(DESTINATION_FILE_NAME, newFileName);
|
||||||
|
})
|
||||||
|
.toD("file://" + destinationPath +
|
||||||
|
"/${exchangeProperty["+DATE_PART_1+"]}" +
|
||||||
|
"/${exchangeProperty["+DATE_PART_2+"]}" +
|
||||||
|
"/${exchangeProperty["+DATE_PART_3+"]}" +
|
||||||
|
"/${exchangeProperty["+DESTINATION_FILE_NAME+"]}")
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package me.bvn13.lesson.camel.testing.cameltesting.danielolivaw;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetFiles {
|
||||||
|
|
||||||
|
public GetFiles() {
|
||||||
|
File parentPath = new File("Desktop/oldBackup");
|
||||||
|
List<String> files = list(parentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<String> list(File parent) {
|
||||||
|
return listFiles(parent, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<String> listFiles(File parent, File folder) {
|
||||||
|
List<String> fileList = new ArrayList<String>();
|
||||||
|
if (folder.isDirectory()) {
|
||||||
|
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
fileList.addAll(listFiles(parent, file));
|
||||||
|
} else {
|
||||||
|
String path = file.getPath();
|
||||||
|
String offset = parent.getPath();
|
||||||
|
|
||||||
|
path = path.substring(offset.length());
|
||||||
|
fileList.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
#camel:
|
camel:
|
||||||
# springboot:
|
springboot:
|
||||||
# main-run-controller: true
|
main-run-controller: true
|
||||||
|
|
||||||
|
|
||||||
app:
|
app:
|
||||||
|
|
Loading…
Reference in New Issue