diff --git a/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java b/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java index f10b89550..ebe906f20 100644 --- a/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java +++ b/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java @@ -16,18 +16,9 @@ */ package org.apache.camel.example.java8; -import java.util.Date; -import java.util.Objects; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.builder.RouteBuilder; import org.apache.camel.main.Main; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public final class MyApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class); private MyApplication() { } @@ -36,42 +27,4 @@ public static void main(String[] args) throws Exception { Main main = new Main(MyApplication.class); main.run(args); } - - static class MyRouteBuilder extends RouteBuilder { - - @Override - public void configure() throws Exception { - from("timer:simple?includeMetadata=true&period=503") - .id("simple-route") - .transform() - .exchange(this::dateToTime) - .process() - .message(this::log) - .process() - .body(this::log) - .choice() - .when() - .body(Integer.class, b -> (b & 1) == 0) - .log("Received even number") - .when() - .body(Integer.class, b -> (b & 1) != 0) - .log("Received odd number") - .when() - .body(Objects::isNull) - .log("Received null body") - .end(); - } - - private Long dateToTime(Exchange e) { - return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime(); - } - - private void log(Object b) { - LOGGER.info("body is: {}", b); - } - - private void log(Message m) { - LOGGER.info("message is: {}", m); - } - } } diff --git a/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java b/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java new file mode 100644 index 000000000..ac25f0e1b --- /dev/null +++ b/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.example.java8; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.builder.RouteBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.Objects; + +public class MyRouteBuilder extends RouteBuilder { + private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class); + + @Override + public void configure() throws Exception { + from("timer:simple?includeMetadata=true&period=503") + .id("simple-route") + .transform() + .exchange(this::dateToTime) + .process() + .message(this::log) + .process() + .body(this::log) + .choice() + .when() + .body(Integer.class, b -> (b & 1) == 0) + .log("Received even number") + .when() + .body(Integer.class, b -> (b & 1) != 0) + .log("Received odd number") + .when() + .body(Objects::isNull) + .log("Received null body") + .end(); + } + + private Long dateToTime(Exchange e) { + return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime(); + } + + private void log(Object b) { + LOGGER.info("body is: {}", b); + } + + private void log(Message m) { + LOGGER.info("message is: {}", m); + } +} diff --git a/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java b/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java index 57eb3ba8b..8ee16592a 100644 --- a/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java +++ b/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java @@ -41,6 +41,6 @@ void should_be_evaluated() { @Override protected void configure(MainConfigurationProperties configuration) { - configuration.addRoutesBuilder(new MyApplication.MyRouteBuilder()); + configuration.addRoutesBuilder(new MyRouteBuilder()); } }