diff --git a/route_java/TempsAttenteAgenceCamel.java b/route_java/TempsAttenteAgenceCamel.java index 069683d..b669873 100644 --- a/route_java/TempsAttenteAgenceCamel.java +++ b/route_java/TempsAttenteAgenceCamel.java @@ -1,39 +1,39 @@ -// camel-k: language=java +///usr/bin/env jbang "$0" "$@" ; exit $? +// Use org.apache.camel:camel-bom:3.19.0@pom in order to avoid repeating the version in each line +//DEPS org.apache.camel:camel-core:3.19.0 +//DEPS org.apache.camel:camel-main:3.19.0 +//DEPS org.apache.camel:camel-stream:3.19.0 +//DEPS org.apache.camel:camel-http:3.19.0 +//DEPS org.apache.camel:camel-jackson:3.19.0 -import org.apache.camel.main.Main; +import org.apache.camel.*; +import org.apache.camel.builder.*; +import org.apache.camel.main.*; +import org.apache.camel.model.dataformat.JsonLibrary; -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.DefaultCamelContext; +import static java.lang.System.*; public class TempsAttenteAgenceCamel { - public static void main() throws Exception { - try (CamelContext camel = new DefaultCamelContext()) { - - camel.addRoutes(new TempsAttenteRouteBuilder()); - camel.start(); - } - catch (Exception e) { - - System.out.println("L'erreur suivante a été soulevé : " + e.toString()); - - } - } - - public static class TempsAttenteRouteBuilder extends RouteBuilder { - @Override - public void configure() { - from("timer://foo?period=5000") - .to("http:8080://temps-attente/agence/4161") - .log("The body was - ${body}"); - - /* from("timer:mytimer?repeatCount=1") - .setBody(simple("${null}")) - .setHeader("agence", constant("4161")) - .toD("localhost:8080/temps-attente/agence/${header.agence}" + "?httpMethod=GET") - .log("The body was - ${body}"); */ - } + public static void main(String... args) throws Exception { + out.println("Hello World"); + out.println("Running camel route..."); + + Main main = new Main(); + + // Configuration de la route + main.configure().addRoutesBuilder(new RouteBuilder() { + public void configure() throws Exception { + from("timer://foo?period=5000") + .to("http://localhost:8080/temps-attente/agences") + .unmarshal().json(JsonLibrary.Jackson) + .process(exchange -> { + // On print la réponse + out.println(exchange.getIn().getBody()); + }); + + } + }); + main.run(); } - }