From 2e6baf3180b077425b22f94445ba6ecbc6c0e761 Mon Sep 17 00:00:00 2001 From: Joe Di Pol Date: Fri, 22 Sep 2023 14:30:39 -0700 Subject: [PATCH] Update examples to not use io.helidon.common.config and to explicitally call Config.global(config) --- .../io/helidon/examples/cors/GreetService.java | 3 ++- .../main/java/io/helidon/examples/cors/Main.java | 13 ++++++------- .../java/io/helidon/examples/cors/MainTest.java | 2 +- .../integrations/micrometer/se/GreetService.java | 3 ++- .../examples/integrations/micrometer/se/Main.java | 12 ++++++++---- .../integrations/micrometer/se/MainTest.java | 2 +- .../examples/metrics/exemplar/GreetService.java | 3 ++- .../helidon/examples/metrics/exemplar/Main.java | 9 +++++---- .../examples/metrics/exemplar/MainTest.java | 3 ++- .../metrics/filtering/se/GreetService.java | 5 +++-- .../examples/metrics/filtering/se/Main.java | 8 ++++---- .../examples/metrics/filtering/se/MainTest.java | 2 +- .../examples/se/httpstatuscount/GreetService.java | 3 ++- .../helidon/examples/se/httpstatuscount/Main.java | 12 ++++++------ .../se/httpstatuscount/SimpleGreetService.java | 3 ++- .../examples/se/httpstatuscount/StatusTest.java | 5 +++-- .../examples/metrics/kpi/GreetService.java | 3 ++- .../io/helidon/examples/metrics/kpi/Main.java | 12 ++++++------ .../io/helidon/examples/openapi/GreetService.java | 3 ++- .../java/io/helidon/examples/openapi/Main.java | 9 +++++---- .../examples/quickstart/se/GreetService.java | 6 +++++- .../io/helidon/examples/quickstart/se/Main.java | 12 +++++++----- .../helidon-standalone-quickstart-se/pom.xml | 4 ++++ .../examples/quickstart/se/GreetService.java | 6 +++++- .../io/helidon/examples/quickstart/se/Main.java | 11 ++++++++--- .../examples/webclient/standalone/ServerMain.java | 13 +++++++------ .../webclient/standalone/ClientMainTest.java | 3 ++- .../webserver/imperative/ImperativeMain.java | 6 +++--- .../webserver/examples/multiport/Main.java | 15 +++++++++------ .../webserver/examples/multiport/MainTest.java | 5 +++-- 30 files changed, 118 insertions(+), 78 deletions(-) diff --git a/examples/cors/src/main/java/io/helidon/examples/cors/GreetService.java b/examples/cors/src/main/java/io/helidon/examples/cors/GreetService.java index 1f7315f3aeb..17271f98d45 100644 --- a/examples/cors/src/main/java/io/helidon/examples/cors/GreetService.java +++ b/examples/cors/src/main/java/io/helidon/examples/cors/GreetService.java @@ -53,7 +53,8 @@ public class GreetService implements HttpService { private static final JsonBuilderFactory JSON_BF = Json.createBuilderFactory(Collections.emptyMap()); - GreetService(Config config) { + GreetService() { + Config config = Config.global(); this.greeting = config.get("app.greeting").asString().orElse("Ciao"); } diff --git a/examples/cors/src/main/java/io/helidon/examples/cors/Main.java b/examples/cors/src/main/java/io/helidon/examples/cors/Main.java index 133b5460acf..5aca1ca0150 100644 --- a/examples/cors/src/main/java/io/helidon/examples/cors/Main.java +++ b/examples/cors/src/main/java/io/helidon/examples/cors/Main.java @@ -47,14 +47,15 @@ public static void main(final String[] args) { // load logging configuration LogConfig.configureRuntime(); - // By default, this will pick up application.yaml from the classpath + // initialize global config from default configuration Config config = Config.create(); + Config.global(config); // Get webserver config from the "server" section of application.yaml WebServerConfig.Builder builder = WebServer.builder(); WebServer server = builder .config(config.get("server")) - .routing(it -> routing(it, config)) + .routing(Main::routing) .build() .start(); @@ -65,14 +66,12 @@ public static void main(final String[] args) { * Setup routing. * * @param routing routing builder - * @param config configuration of this server */ - static void routing(HttpRouting.Builder routing, Config config) { - - GreetService greetService = new GreetService(config); + static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); // Note: Add the CORS routing *before* registering the GreetService routing. - routing.register("/greet", corsSupportForGreeting(config), greetService) + routing.register("/greet", corsSupportForGreeting(config), new GreetService()) .addFeature(ObserveFeature.create()); } diff --git a/examples/cors/src/test/java/io/helidon/examples/cors/MainTest.java b/examples/cors/src/test/java/io/helidon/examples/cors/MainTest.java index 232c7687cd0..ea678842535 100644 --- a/examples/cors/src/test/java/io/helidon/examples/cors/MainTest.java +++ b/examples/cors/src/test/java/io/helidon/examples/cors/MainTest.java @@ -62,7 +62,7 @@ public class MainTest { @SetUpServer public static void setup(WebServerConfig.Builder server) { - server.routing(routing -> Main.routing(routing, Config.create())); + server.routing(routing -> Main.routing(routing)); } @Order(1) // Make sure this runs before the greeting message changes so responses are deterministic. diff --git a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/GreetService.java b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/GreetService.java index 58d5b6592b8..366681f606e 100644 --- a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/GreetService.java +++ b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/GreetService.java @@ -64,7 +64,8 @@ public class GreetService implements HttpService { private static final JsonBuilderFactory JSON_BF = Json.createBuilderFactory(Collections.emptyMap()); - GreetService(Config config, Timer getTimer, Counter personalizedGetCounter) { + GreetService(Timer getTimer, Counter personalizedGetCounter) { + Config config = Config.global(); this.greeting = config.get("app.greeting").asString().orElse("Ciao"); this.getTimer = getTimer; this.personalizedGetCounter = personalizedGetCounter; diff --git a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/Main.java b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/Main.java index f605cda5e94..bc260a9aa67 100644 --- a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/Main.java +++ b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/integrations/micrometer/se/Main.java @@ -57,11 +57,13 @@ static WebServer startServer() { LogConfig.configureRuntime(); // By default, this will pick up application.yaml from the classpath + // and initialize global config Config config = Config.create(); + Config.global(config); WebServer server = WebServer.builder() .config(config.get("server")) - .routing(r -> setupRouting(r, config)) + .routing(Main::setupRouting) .build() .start(); @@ -73,9 +75,11 @@ static WebServer startServer() { * Setup routing. * * @param routing routing builder - * @param config config */ - static void setupRouting(HttpRouting.Builder routing, Config config) { + static void setupRouting(HttpRouting.Builder routing) { + + Config config = Config.global(); + MicrometerFeature micrometerSupport = MicrometerFeature.create(config); Counter personalizedGetCounter = micrometerSupport.registry() .counter(PERSONALIZED_GETS_COUNTER_NAME); @@ -83,7 +87,7 @@ static void setupRouting(HttpRouting.Builder routing, Config config) { .publishPercentileHistogram() .register(micrometerSupport.registry()); - GreetService greetService = new GreetService(config, getTimer, personalizedGetCounter); + GreetService greetService = new GreetService(getTimer, personalizedGetCounter); routing.register("/greet", greetService) .addFeature(micrometerSupport); diff --git a/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/integrations/micrometer/se/MainTest.java b/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/integrations/micrometer/se/MainTest.java index 04574b41673..42d2dc60b68 100644 --- a/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/integrations/micrometer/se/MainTest.java +++ b/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/integrations/micrometer/se/MainTest.java @@ -62,7 +62,7 @@ public MainTest(Http1Client client) { @SetUpServer public static void setup(Builder builder) { - builder.routing(r -> Main.setupRouting(r, Config.create())); + builder.routing(Main::setupRouting); } @Test diff --git a/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/GreetService.java b/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/GreetService.java index 17033a78f24..f091be1225e 100644 --- a/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/GreetService.java +++ b/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/GreetService.java @@ -64,7 +64,8 @@ public class GreetService implements HttpService { private final Timer timerForGets; private final Counter personalizedGreetingsCounter; - GreetService(Config config) { + GreetService() { + Config config = Config.global(); greeting.set(config.get("app.greeting").asString().orElse("Ciao")); MeterRegistry meterRegistry = Metrics.globalRegistry(); diff --git a/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/Main.java b/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/Main.java index bde4b77a7ff..87ba1899fda 100644 --- a/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/Main.java +++ b/examples/metrics/exemplar/src/main/java/io/helidon/examples/metrics/exemplar/Main.java @@ -60,8 +60,9 @@ static void setup(WebServerConfig.Builder server) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); - server.routing(r -> routing(r, config)) + server.routing(Main::routing) .config(config.get("server")); } @@ -70,12 +71,12 @@ static void setup(WebServerConfig.Builder server) { * Setup routing. * * @param routing routing builder - * @param config configuration of this server */ - static void routing(HttpRouting.Builder routing, Config config) { + static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); Tracer tracer = TracerBuilder.create(config.get("tracing")).build(); routing.addFeature(ObserveFeature.create()) .addFeature(TracingFeature.create(tracer)) - .register("/greet", new GreetService(config)); + .register("/greet", new GreetService()); } } diff --git a/examples/metrics/exemplar/src/test/java/io/helidon/examples/metrics/exemplar/MainTest.java b/examples/metrics/exemplar/src/test/java/io/helidon/examples/metrics/exemplar/MainTest.java index 87401988436..a50898dca4a 100644 --- a/examples/metrics/exemplar/src/test/java/io/helidon/examples/metrics/exemplar/MainTest.java +++ b/examples/metrics/exemplar/src/test/java/io/helidon/examples/metrics/exemplar/MainTest.java @@ -56,7 +56,8 @@ public MainTest(Http1Client client) { @SetUpServer public static void setup(WebServerConfig.Builder server) { - server.routing(it -> Main.routing(it, Config.create())); + Config.global(Config.create()); + server.routing(Main::routing); } @Test diff --git a/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/GreetService.java b/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/GreetService.java index 371643187ff..29c0a4def0d 100644 --- a/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/GreetService.java +++ b/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/GreetService.java @@ -19,7 +19,7 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; -import io.helidon.common.config.Config; +import io.helidon.config.Config; import io.helidon.http.Status; import io.helidon.metrics.api.Counter; import io.helidon.metrics.api.MeterRegistry; @@ -63,7 +63,8 @@ public class GreetService implements HttpService { private final Timer timerForGets; private final Counter personalizedGreetingsCounter; - GreetService(Config config, MeterRegistry meterRegistry) { + GreetService(MeterRegistry meterRegistry) { + Config config = Config.global(); greeting.set(config.get("app.greeting").asString().orElse("Ciao")); timerForGets = meterRegistry.getOrCreate(Timer.builder(TIMER_FOR_GETS)); personalizedGreetingsCounter = meterRegistry.getOrCreate(Counter.builder(COUNTER_FOR_PERSONALIZED_GREETINGS)); diff --git a/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/Main.java b/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/Main.java index 58587761205..f0ab8cd6e3a 100644 --- a/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/Main.java +++ b/examples/metrics/filtering/se/src/main/java/io/helidon/examples/metrics/filtering/se/Main.java @@ -18,8 +18,7 @@ import java.util.regex.Pattern; -import io.helidon.common.config.Config; -import io.helidon.common.config.GlobalConfig; +import io.helidon.config.Config; import io.helidon.logging.common.LogConfig; import io.helidon.metrics.api.Meter; import io.helidon.metrics.api.MeterRegistry; @@ -67,7 +66,8 @@ static void setup(WebServerConfig.Builder server) { LogConfig.configureRuntime(); // By default, this will pick up application.yaml from the classpath - Config config = GlobalConfig.config(); + Config config = Config.create(); + Config.global(config); // Programmatically (not through config), tell the metrics feature to ignore the "gets" timer. // To do so, create the scope config, then add it to the metrics config that ultimately @@ -100,7 +100,7 @@ static void routing(HttpRouting.Builder routing, Config config, MetricsConfig.Bu MetricsObserver metrics = MetricsObserver.builder() .metricsConfig(metricsConfigBuilder) .build(); - GreetService greetService = new GreetService(config, meterRegistry); + GreetService greetService = new GreetService(meterRegistry); routing.addFeature(ObserveFeature.just(metrics)) .register("/greet", greetService); diff --git a/examples/metrics/filtering/se/src/test/java/io/helidon/examples/metrics/filtering/se/MainTest.java b/examples/metrics/filtering/se/src/test/java/io/helidon/examples/metrics/filtering/se/MainTest.java index d4fc40f89ce..8a06d8a3c73 100644 --- a/examples/metrics/filtering/se/src/test/java/io/helidon/examples/metrics/filtering/se/MainTest.java +++ b/examples/metrics/filtering/se/src/test/java/io/helidon/examples/metrics/filtering/se/MainTest.java @@ -36,7 +36,6 @@ import static org.hamcrest.Matchers.not; @ServerTest -@Disabled public class MainTest { private static final JsonBuilderFactory JSON_BUILDER = Json.createBuilderFactory(Collections.emptyMap()); @@ -79,6 +78,7 @@ public void testHelloWorld() { } @Test + @Disabled // application metrics returns 404 public void testMetrics() { try (Http1ClientResponse response = client.get("/greet").request()) { assertThat(response.as(String.class), containsString("Hello World!")); diff --git a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/GreetService.java b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/GreetService.java index 5a14c09ebb0..9484e4691b2 100644 --- a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/GreetService.java +++ b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/GreetService.java @@ -53,7 +53,8 @@ public class GreetService implements HttpService { private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap()); - GreetService(Config config) { + GreetService() { + Config config = Config.global(); greeting.set(config.get("app.greeting").asString().orElse("Ciao")); } diff --git a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/Main.java b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/Main.java index ec8dbbc24ca..0c2ec8ed14d 100644 --- a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/Main.java +++ b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/Main.java @@ -56,8 +56,9 @@ static void setup(WebServerConfig.Builder server) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); - server.routing(r -> routing(r, config)) + server.routing(Main::routing) .config(config.get("server")); } @@ -68,12 +69,11 @@ static void setup(WebServerConfig.Builder server) { * @param routing routing builder * @param config configuration of this server */ - static void routing(HttpRouting.Builder routing, Config config) { - SimpleGreetService simpleGreetService = new SimpleGreetService(config); - GreetService greetService = new GreetService(config); + static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); routing.addFeature(ObserveFeature.create()) .register(HttpStatusMetricService.create()) // no endpoint, just metrics updates - .register("/simple-greet", simpleGreetService) - .register("/greet", greetService); + .register("/simple-greet", new SimpleGreetService()) + .register("/greet", new GreetService()); } } diff --git a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/SimpleGreetService.java b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/SimpleGreetService.java index 356f6df7ea5..0b8aa40e92c 100644 --- a/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/SimpleGreetService.java +++ b/examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/SimpleGreetService.java @@ -49,7 +49,8 @@ public class SimpleGreetService implements HttpService { private final String greeting; - SimpleGreetService(Config config) { + SimpleGreetService() { + Config config = Config.global(); greeting = config.get("app.greeting").asString().orElse("Ciao"); } diff --git a/examples/metrics/http-status-count-se/src/test/java/io/helidon/examples/se/httpstatuscount/StatusTest.java b/examples/metrics/http-status-count-se/src/test/java/io/helidon/examples/se/httpstatuscount/StatusTest.java index b8d3751c64d..561b903a20c 100644 --- a/examples/metrics/http-status-count-se/src/test/java/io/helidon/examples/se/httpstatuscount/StatusTest.java +++ b/examples/metrics/http-status-count-se/src/test/java/io/helidon/examples/se/httpstatuscount/StatusTest.java @@ -43,7 +43,6 @@ import static org.junit.jupiter.api.Assertions.fail; @ServerTest -@Disabled public class StatusTest { private final Counter[] STATUS_COUNTERS = new Counter[6]; @@ -55,8 +54,9 @@ public StatusTest(Http1Client client) { @SetUpServer public static void setup(WebServerConfig.Builder server) { + Config.global(Config.create()); server.routing(r -> { - Main.routing(r, Config.create()); + Main.routing(r); r.register("/status", new StatusService()); }); } @@ -71,6 +71,7 @@ void findStatusMetrics() { } @Test + @Disabled void checkStatusMetrics() throws InterruptedException { checkAfterStatus(Status.create(171)); checkAfterStatus(Status.OK_200); diff --git a/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/GreetService.java b/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/GreetService.java index f6dc74ac2a8..6f8a92aeaf6 100644 --- a/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/GreetService.java +++ b/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/GreetService.java @@ -66,7 +66,8 @@ public class GreetService implements HttpService { private final Counter personalizedGreetingsCounter; - GreetService(Config config) { + GreetService() { + Config config = Config.global(); greeting.set(config.get("app.greeting").asString().orElse("Ciao")); MeterRegistry meterRegistry = Metrics.globalRegistry(); timerForGets = meterRegistry.getOrCreate(Timer.builder(TIMER_FOR_GETS) diff --git a/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/Main.java b/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/Main.java index 9497a38c2f5..9b085f5b698 100644 --- a/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/Main.java +++ b/examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/Main.java @@ -66,8 +66,9 @@ static void setup(WebServerConfig.Builder server) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); - server.routing(r -> routing(r, config)) + server.routing(Main::routing) .config(config.get("server")); } @@ -76,9 +77,10 @@ static void setup(WebServerConfig.Builder server) { * Setup routing. * * @param routing routing builder - * @param config configuration of this server */ - private static void routing(HttpRouting.Builder routing, Config config) { + private static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); + /* * For purposes of illustration, the key performance indicator settings for the * MetricsSupport instance are set up according to a system property, so you can see, @@ -89,10 +91,8 @@ private static void routing(HttpRouting.Builder routing, Config config) { ? metricsSupportWithConfig(config.get("metrics")) : metricsSupportWithoutConfig(); - GreetService greetService = new GreetService(config); - routing.addFeature(ObserveFeature.just(metricsSupport)) - .register("/greet", greetService); + .register("/greet", new GreetService()); } /** diff --git a/examples/openapi/src/main/java/io/helidon/examples/openapi/GreetService.java b/examples/openapi/src/main/java/io/helidon/examples/openapi/GreetService.java index 6dbde8fd8a6..be82d5ab07c 100644 --- a/examples/openapi/src/main/java/io/helidon/examples/openapi/GreetService.java +++ b/examples/openapi/src/main/java/io/helidon/examples/openapi/GreetService.java @@ -52,7 +52,8 @@ public class GreetService implements HttpService { private static final JsonBuilderFactory JSON_BF = Json.createBuilderFactory(Map.of()); - GreetService(Config config) { + GreetService() { + Config config = Config.global(); this.greeting = config.get("app.greeting").asString().orElse("Ciao"); } diff --git a/examples/openapi/src/main/java/io/helidon/examples/openapi/Main.java b/examples/openapi/src/main/java/io/helidon/examples/openapi/Main.java index e3cb960487e..918844a889f 100644 --- a/examples/openapi/src/main/java/io/helidon/examples/openapi/Main.java +++ b/examples/openapi/src/main/java/io/helidon/examples/openapi/Main.java @@ -59,22 +59,23 @@ static void setup(WebServerConfig.Builder server) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); server.config(config.get("server")) - .routing(r -> routing(r, config)); + .routing(Main::routing); } /** * Set up routing. * * @param routing routing builder - * @param config configuration of this server */ - static void routing(HttpRouting.Builder routing, Config config) { + static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); routing.addFeature(ObserveFeature.create()) .addFeature(OpenApiFeature.builder() .config(config.get(OpenApiFeature.Builder.CONFIG_KEY))) - .register("/greet", new GreetService(config)); + .register("/greet", new GreetService()); } } diff --git a/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java b/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java index a14fe613480..4f098af3d97 100644 --- a/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java +++ b/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java @@ -19,7 +19,7 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; -import io.helidon.common.config.Config; +import io.helidon.config.Config; import io.helidon.http.Status; import io.helidon.webserver.http.HttpRules; import io.helidon.webserver.http.HttpService; @@ -53,6 +53,10 @@ public class GreetService implements HttpService { */ private final AtomicReference greeting = new AtomicReference<>(); + GreetService() { + this(Config.global().get("app")); + } + GreetService(Config appConfig) { greeting.set(appConfig.get("greeting").asString().orElse("Ciao")); } diff --git a/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java b/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java index af8425e069a..7d9428c51d2 100644 --- a/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java +++ b/examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java @@ -43,8 +43,12 @@ public static void main(String[] args) { // load logging configuration LogConfig.configureRuntime(); + // initialize global config from default configuration + Config config = Config.create(); + Config.global(config); + WebServer server = WebServer.builder() - .config(Config.global().get("server")) + .config(config.get("server")) .routing(Main::routing) .build() .start(); @@ -58,10 +62,8 @@ public static void main(String[] args) { static void routing(HttpRouting.Builder routing) { Config config = Config.global(); - OpenApiFeature openApi = OpenApiFeature.create(config.get("openapi")); - GreetService greetService = new GreetService(config.get("app")); - routing.addFeature(openApi) - .register("/greet", greetService) + routing.register("/greet", new GreetService()) + .addFeature(OpenApiFeature.create(config.get("openapi"))) .addFeature(ObserveFeature.create(config.get("observe"))); } } diff --git a/examples/quickstarts/helidon-standalone-quickstart-se/pom.xml b/examples/quickstarts/helidon-standalone-quickstart-se/pom.xml index 8dc917c98a6..315435c6cb8 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-se/pom.xml +++ b/examples/quickstarts/helidon-standalone-quickstart-se/pom.xml @@ -85,6 +85,10 @@ helidon-metrics-system-meters runtime + + io.helidon.openapi + helidon-openapi + io.helidon.config helidon-config-yaml diff --git a/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java b/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java index a14fe613480..4f098af3d97 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java +++ b/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java @@ -19,7 +19,7 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; -import io.helidon.common.config.Config; +import io.helidon.config.Config; import io.helidon.http.Status; import io.helidon.webserver.http.HttpRules; import io.helidon.webserver.http.HttpService; @@ -53,6 +53,10 @@ public class GreetService implements HttpService { */ private final AtomicReference greeting = new AtomicReference<>(); + GreetService() { + this(Config.global().get("app")); + } + GreetService(Config appConfig) { greeting.set(appConfig.get("greeting").asString().orElse("Ciao")); } diff --git a/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java b/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java index d35eb32321a..7d9428c51d2 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java +++ b/examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java @@ -18,6 +18,7 @@ import io.helidon.config.Config; import io.helidon.logging.common.LogConfig; +import io.helidon.openapi.OpenApiFeature; import io.helidon.webserver.WebServer; import io.helidon.webserver.http.HttpRouting; import io.helidon.webserver.observe.ObserveFeature; @@ -42,8 +43,12 @@ public static void main(String[] args) { // load logging configuration LogConfig.configureRuntime(); + // initialize global config from default configuration + Config config = Config.create(); + Config.global(config); + WebServer server = WebServer.builder() - .config(Config.global().get("server")) + .config(config.get("server")) .routing(Main::routing) .build() .start(); @@ -57,8 +62,8 @@ public static void main(String[] args) { static void routing(HttpRouting.Builder routing) { Config config = Config.global(); - GreetService greetService = new GreetService(config.get("app")); - routing.register("/greet", greetService) + routing.register("/greet", new GreetService()) + .addFeature(OpenApiFeature.create(config.get("openapi"))) .addFeature(ObserveFeature.create(config.get("observe"))); } } diff --git a/examples/webclient/standalone/src/main/java/io/helidon/examples/webclient/standalone/ServerMain.java b/examples/webclient/standalone/src/main/java/io/helidon/examples/webclient/standalone/ServerMain.java index c2fed3a7553..27490389489 100644 --- a/examples/webclient/standalone/src/main/java/io/helidon/examples/webclient/standalone/ServerMain.java +++ b/examples/webclient/standalone/src/main/java/io/helidon/examples/webclient/standalone/ServerMain.java @@ -40,9 +40,10 @@ private ServerMain() { public static void main(String[] args) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); WebServerConfig.Builder builder = WebServer.builder(); - setup(builder, config); + setup(builder); WebServer server = builder.build().start(); server.context().register(server); System.out.println("WEB server is up! http://localhost:" + server.port() + "/greet"); @@ -52,20 +53,20 @@ public static void main(String[] args) { * Set up the server. * * @param server server builder - * @param config config */ - static void setup(WebServerConfig.Builder server, Config config) { + static void setup(WebServerConfig.Builder server) { + Config config = Config.global(); server.config(config.get("server")) - .routing(r -> routing(r, config)); + .routing(ServerMain::routing); } /** * Setup routing. * * @param routing routing builder - * @param config configuration of this server */ - private static void routing(HttpRouting.Builder routing, Config config) { + private static void routing(HttpRouting.Builder routing) { + Config config = Config.global(); routing.addFeature(ObserveFeature.create()) .register("/greet", new GreetService(config)); } diff --git a/examples/webclient/standalone/src/test/java/io/helidon/examples/webclient/standalone/ClientMainTest.java b/examples/webclient/standalone/src/test/java/io/helidon/examples/webclient/standalone/ClientMainTest.java index f7a4a69ea15..cd3bc35d944 100644 --- a/examples/webclient/standalone/src/test/java/io/helidon/examples/webclient/standalone/ClientMainTest.java +++ b/examples/webclient/standalone/src/test/java/io/helidon/examples/webclient/standalone/ClientMainTest.java @@ -61,7 +61,8 @@ public ClientMainTest(WebServer server) { @SetUpServer public static void setup(WebServerConfig.Builder server) { - ServerMain.setup(server, Config.create()); + Config.global(Config.create()); + ServerMain.setup(server); } @AfterEach diff --git a/examples/webserver/imperative/src/main/java/io/helidon/examples/webserver/imperative/ImperativeMain.java b/examples/webserver/imperative/src/main/java/io/helidon/examples/webserver/imperative/ImperativeMain.java index 4960de5f347..a7ee931d646 100644 --- a/examples/webserver/imperative/src/main/java/io/helidon/examples/webserver/imperative/ImperativeMain.java +++ b/examples/webserver/imperative/src/main/java/io/helidon/examples/webserver/imperative/ImperativeMain.java @@ -16,8 +16,7 @@ package io.helidon.examples.webserver.imperative; -import io.helidon.common.config.Config; -import io.helidon.common.config.GlobalConfig; +import io.helidon.config.Config; import io.helidon.http.Method; import io.helidon.webserver.WebServer; import io.helidon.webserver.http.HttpRouting; @@ -35,7 +34,8 @@ private ImperativeMain() { * @param args ignored */ public static void main(String[] args) { - Config config = GlobalConfig.config(); + Config config = Config.create(); + Config.global(config); WebServer server = WebServer.create(ws -> ws.config(config.get("server")) .routing(ImperativeMain::routing)) diff --git a/examples/webserver/multiport/src/main/java/io/helidon/webserver/examples/multiport/Main.java b/examples/webserver/multiport/src/main/java/io/helidon/webserver/examples/multiport/Main.java index 5f10e8c6fb7..e03f6ab5988 100644 --- a/examples/webserver/multiport/src/main/java/io/helidon/webserver/examples/multiport/Main.java +++ b/examples/webserver/multiport/src/main/java/io/helidon/webserver/examples/multiport/Main.java @@ -45,21 +45,24 @@ public static void main(final String[] args) { // By default, this will pick up application.yaml from the classpath Config config = Config.create(); + Config.global(config); + + WebServer server = WebServer.builder() + .config(config.get("server")) + .update(Main::setup) + .build() + .start(); - WebServerConfig.Builder builder = WebServer.builder(); - setup(builder, config); - WebServer server = builder.build().start(); System.out.println("WEB server is up! http://localhost:" + server.port()); } /** * Set up the server. */ - static void setup(WebServerConfig.Builder server, Config config) { + static void setup(WebServerConfig.Builder server) { // Build server using three ports: // default public port, admin port, private port - server.config(config.get("server")) - .routing(Main::publicRouting) + server.routing(Main::publicRouting) // Add a set of routes on the named socket "admin" .putSocket("admin", socket -> socket.from(server.sockets().get("admin")) .routing(Main::adminSocket)) diff --git a/examples/webserver/multiport/src/test/java/io/helidon/webserver/examples/multiport/MainTest.java b/examples/webserver/multiport/src/test/java/io/helidon/webserver/examples/multiport/MainTest.java index ba396191513..2f70692955a 100644 --- a/examples/webserver/multiport/src/test/java/io/helidon/webserver/examples/multiport/MainTest.java +++ b/examples/webserver/multiport/src/test/java/io/helidon/webserver/examples/multiport/MainTest.java @@ -61,8 +61,9 @@ int port(Params params) { @SetUpServer public static void setup(WebServerConfig.Builder server) { // Use test configuration so we can have ports allocated dynamically - Config config = Config.builder().addSource(ConfigSources.classpath("application-test.yaml")).build(); - Main.setup(server, config); + Config config = Config.just(ConfigSources.classpath("application-test.yaml")); + server.config(config.get("server")) + .update(Main::setup); } static Stream initParams() {