From 692a64333b7850f36507bd2347e6e27f9e79ce9f Mon Sep 17 00:00:00 2001 From: aserkes Date: Fri, 19 May 2023 20:44:18 +0200 Subject: [PATCH] Update examples/logging/logback-aot to use Nima Signed-off-by: aserkes --- examples/logging/logback-aot/README.md | 12 +++---- examples/logging/logback-aot/pom.xml | 4 +-- .../examples/logging/logback/aot/Main.java | 33 +++++++++---------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/examples/logging/logback-aot/README.md b/examples/logging/logback-aot/README.md index 30c560c1e1b..c4a6be6559d 100644 --- a/examples/logging/logback-aot/README.md +++ b/examples/logging/logback-aot/README.md @@ -18,11 +18,11 @@ Within 30 seconds the configuration should be reloaded, and next request will ha Expected output should be similar to the following (for both hotspot and native): ```text -15:40:44.240 INFO [main] i.h.examples.logging.slf4j.Main - Starting up startup -15:40:44.241 INFO [main] i.h.examples.logging.slf4j.Main - Using JUL logger startup -15:40:44.245 INFO [pool-1-thread-1] i.h.examples.logging.slf4j.Main - Running on another thread propagated -15:40:44.395 INFO [features-thread] io.helidon.common.features.HelidonFeatures - Helidon SE 2.2.0 features: [Config, WebServer] -15:40:44.538 INFO [nioEventLoopGroup-2-1] io.helidon.reactive.webserver.NettyWebServer - Channel '@default' started: [id: 0x8e516487, L:/0:0:0:0:0:0:0:0:8080] +15:40:44.240 [INFO ] [io.helidon.examples.logging.logback.aot.Main.logging:128] Starting up startup +15:40:44.241 [INFO ] [o.slf4j.jdk.platform.logging.SLF4JPlatformLogger.performLog:151] Using System logger startup +15:40:44.245 [INFO ] [io.helidon.examples.logging.logback.aot.Main.log:146] Running on another thread propagated +15:40:44.395 [INFO ] [o.slf4j.jdk.platform.logging.SLF4JPlatformLogger.performLog:151] Helidon NIMA 4.0.0-SNAPSHOT features: [Config, Encoding, Media, WebServer] +15:40:44.538 [INFO ] [o.slf4j.jdk.platform.logging.SLF4JPlatformLogger.performLog:151] Started all channels in 15 milliseconds. 647 milliseconds since JVM startup. Java 20.0.1+9-29 propagated ``` The output is also logged into `helidon.log`. @@ -36,7 +36,7 @@ mvn clean package Run from command line: ```shell script -java -jar target/helidon-examples-logging-sfl4j.jar +java -jar target/helidon-examples-logging-slf4j-aot.jar ``` Execute endpoint: diff --git a/examples/logging/logback-aot/pom.xml b/examples/logging/logback-aot/pom.xml index add733a0905..b48865b4900 100644 --- a/examples/logging/logback-aot/pom.xml +++ b/examples/logging/logback-aot/pom.xml @@ -42,8 +42,8 @@ - io.helidon.reactive.webserver - helidon-reactive-webserver + io.helidon.nima.webserver + helidon-nima-webserver io.helidon.logging diff --git a/examples/logging/logback-aot/src/main/java/io/helidon/examples/logging/logback/aot/Main.java b/examples/logging/logback-aot/src/main/java/io/helidon/examples/logging/logback/aot/Main.java index 470b18c764b..e832f19cafc 100644 --- a/examples/logging/logback-aot/src/main/java/io/helidon/examples/logging/logback/aot/Main.java +++ b/examples/logging/logback-aot/src/main/java/io/helidon/examples/logging/logback/aot/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022 Oracle and/or its affiliates. + * Copyright (c) 2021, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,12 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import io.helidon.common.context.Context; import io.helidon.common.context.Contexts; import io.helidon.logging.common.HelidonMdc; -import io.helidon.reactive.webserver.Routing; -import io.helidon.reactive.webserver.WebServer; +import io.helidon.nima.webserver.WebServer; +import io.helidon.nima.webserver.http.HttpRouting; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; @@ -60,20 +59,20 @@ public static void main(String[] args) { // done by the webserver Contexts.runInContext(Context.create(), Main::logging); - WebServer.builder() - .routing(Routing.builder() - .get("/", (req, res) -> { - HelidonMdc.set("name", String.valueOf(req.requestId())); - LOGGER.debug("Debug message to show runtime reloading works"); - LOGGER.info("Running in webserver, id:"); - res.send("Hello") - .forSingle(ignored -> LOGGER.debug("Response sent")); - }) - .build()) + WebServer server = WebServer.builder() .port(8080) - .build() - .start() - .await(10, TimeUnit.SECONDS); + .routing(Main::routing) + .start(); + } + + private static void routing(HttpRouting.Builder routing) { + routing.get("/", (req, res) -> { + HelidonMdc.set("name", String.valueOf(req.id())); + LOGGER.debug("Debug message to show runtime reloading works"); + LOGGER.info("Running in webserver, id:"); + res.send("Hello"); + LOGGER.debug("Response sent"); + }); } private static void setupLogging() {