From 29366b669816657126d8968f4012cc9a4e536317 Mon Sep 17 00:00:00 2001 From: Joe DiPol Date: Mon, 4 May 2020 12:46:19 -0700 Subject: [PATCH] Update examples (#1715) * Update examples to get rid of deprecated methods. Don't use Application classes when not needed Remove references to JDK8 in readmes And other minor changes --- examples/config/basics/README.md | 3 +- examples/config/changes/README.md | 3 +- examples/config/git/README.md | 1 - examples/config/mapping/README.md | 3 +- examples/config/overrides/README.md | 3 +- examples/config/sources/README.md | 1 - examples/employee-app/README.md | 1 - examples/grpc/basics/README.md | 7 +- .../helidon/grpc/examples/basics/Server.java | 6 +- examples/grpc/metrics/README.md | 3 +- examples/grpc/security-abac/README.md | 3 +- examples/grpc/security-outbound/README.md | 3 +- examples/grpc/security/README.md | 3 +- examples/health/basics/README.md | 12 +++- examples/health/basics/pom.xml | 15 ++++ .../helidon/examples/health/basics/Main.java | 6 +- .../cdi/datasource-hikaricp-h2/README.md | 1 - .../cdi/datasource-hikaricp-mysql/README.md | 1 - .../cdi/datasource-hikaricp/README.md | 3 +- examples/integrations/cdi/jedis/README.md | 4 +- .../examples/jedis/jaxrs/Application.java | 62 ----------------- examples/integrations/cdi/jpa/README.md | 2 +- .../cdi/oci-objectstorage/README.md | 4 +- .../oci/objectstorage/jaxrs/Application.java | 60 ---------------- .../explicit/HelloWorldApplication.java | 38 ----------- .../example/helloworld/explicit/Main.java | 3 +- .../hello-world-implicit/README.md | 1 - .../implicit/HelloWorldApplication.java | 39 ----------- .../implicit/ImplicitHelloWorldTest.java | 10 ++- examples/microprofile/idcs/README.md | 1 - .../sse/MessagingExampleResource.java | 10 +++ .../sse/MessagingSseExampleApplication.java | 41 ----------- .../messaging/sse/MsgProcessingBean.java | 35 ++++++++++ .../sse/{Main.java => package-info.java} | 21 +----- .../microprofile/mp1_1-security/README.md | 1 - .../mp1_1-static-content/README.md | 1 - .../microprofile/example/staticc/Main.java | 4 +- .../example/staticc/StaticContentApp.java | 37 ---------- examples/microprofile/oidc/README.md | 5 +- .../security/oidc/OidcTestApplication.java | 36 ---------- examples/microprofile/openapi-basic/README.md | 1 - .../openapi/basic/GreetApplication.java | 36 ---------- examples/microprofile/pom.xml | 3 +- examples/microprofile/websocket/README.md | 1 - .../io/helidon/examples/openapi/Main.java | 2 +- .../attribute-based-access-control/README.md | 3 +- examples/security/google-login/README.md | 3 +- examples/security/idcs-login/README.md | 1 - examples/security/jersey/README.md | 3 +- .../examples/jersey/JerseyBuilderMain.java | 19 ++++-- .../security/nohttp-programmatic/README.md | 3 +- examples/security/outbound-override/README.md | 3 +- .../security/webserver-digest-auth/README.md | 3 +- .../digest/DigestExampleBuilderMain.java | 49 +++++++++++-- .../security/webserver-signatures/README.md | 3 +- .../SignatureExampleBuilderMain.java | 21 ++++-- examples/todo-app/frontend/package.json | 1 + examples/webserver/basics/README.md | 1 - .../webserver/examples/basics/Main.java | 68 +++++++++++-------- .../webserver/examples/basics/NameReader.java | 54 +++++++++++++++ .../webserver/examples/basics/MainTest.java | 10 +-- examples/webserver/comment-aas/README.md | 3 +- examples/webserver/jersey/README.md | 3 +- examples/webserver/static-content/README.md | 1 - examples/webserver/streaming/README.md | 3 +- examples/webserver/tutorial/README.md | 3 +- examples/webserver/websocket/README.md | 3 +- .../webserver/testsupport/TestClient.java | 31 ++++++--- .../webserver/testsupport/TestRequest.java | 4 +- .../webserver/testsupport/TestWebServer.java | 18 ++++- 70 files changed, 335 insertions(+), 515 deletions(-) delete mode 100644 examples/integrations/cdi/jedis/src/main/java/io/helidon/integrations/examples/jedis/jaxrs/Application.java delete mode 100644 examples/integrations/cdi/oci-objectstorage/src/main/java/io/helidon/integrations/examples/oci/objectstorage/jaxrs/Application.java delete mode 100644 examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/HelloWorldApplication.java delete mode 100644 examples/microprofile/hello-world-implicit/src/main/java/io/helidon/microprofile/example/helloworld/implicit/HelloWorldApplication.java delete mode 100644 examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingSseExampleApplication.java rename examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/{Main.java => package-info.java} (66%) delete mode 100644 examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/StaticContentApp.java delete mode 100644 examples/microprofile/oidc/src/main/java/io/helidon/examples/microprofile/security/oidc/OidcTestApplication.java delete mode 100644 examples/microprofile/openapi-basic/src/main/java/io/helidon/microprofile/examples/openapi/basic/GreetApplication.java create mode 100644 examples/webserver/basics/src/main/java/io/helidon/webserver/examples/basics/NameReader.java diff --git a/examples/config/basics/README.md b/examples/config/basics/README.md index 6a033cc01..aa2aa316b 100644 --- a/examples/config/basics/README.md +++ b/examples/config/basics/README.md @@ -10,8 +10,7 @@ containing config in HOCON (Human-Optimized Config Object Notation) format ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-config-basics.jar -``` \ No newline at end of file +``` diff --git a/examples/config/changes/README.md b/examples/config/changes/README.md index 74ec71696..2f5ad685d 100644 --- a/examples/config/changes/README.md +++ b/examples/config/changes/README.md @@ -30,8 +30,7 @@ the most up-to-date value. Sometimes that is all you need. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-config-changes.jar -``` \ No newline at end of file +``` diff --git a/examples/config/git/README.md b/examples/config/git/README.md index c7c3e2f1a..17317d064 100644 --- a/examples/config/git/README.md +++ b/examples/config/git/README.md @@ -21,7 +21,6 @@ checks to make sure the value is the expected `hello`. ## Build and run -With JDK8+ ```bash mvn package export ENVIRONMENT_NAME=test diff --git a/examples/config/mapping/README.md b/examples/config/mapping/README.md index 7cdc82a69..d8d561f3a 100644 --- a/examples/config/mapping/README.md +++ b/examples/config/mapping/README.md @@ -17,8 +17,7 @@ system how to construct a POJO instance. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-config-mapping.jar -``` \ No newline at end of file +``` diff --git a/examples/config/overrides/README.md b/examples/config/overrides/README.md index 23be00dc5..3d539e3fe 100644 --- a/examples/config/overrides/README.md +++ b/examples/config/overrides/README.md @@ -21,8 +21,7 @@ take precedence over the settings in the original config sources. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-config-overrides.jar -``` \ No newline at end of file +``` diff --git a/examples/config/sources/README.md b/examples/config/sources/README.md index cc6c36e8a..27e205098 100644 --- a/examples/config/sources/README.md +++ b/examples/config/sources/README.md @@ -17,7 +17,6 @@ filter. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-config-sources.jar diff --git a/examples/employee-app/README.md b/examples/employee-app/README.md index 30547125b..25f8aeaa6 100644 --- a/examples/employee-app/README.md +++ b/examples/employee-app/README.md @@ -13,7 +13,6 @@ The service uses Helidon DB Client that provides reactive and non-blocking acces ## Build and run -With JDK8+ ```bash mvn package java -jar target/employee-app.jar diff --git a/examples/grpc/basics/README.md b/examples/grpc/basics/README.md index 01844c3c7..ec896afd0 100644 --- a/examples/grpc/basics/README.md +++ b/examples/grpc/basics/README.md @@ -4,7 +4,6 @@ A basic example gRPC server. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-grpc-basics.jar @@ -14,4 +13,8 @@ Exercise the example: ```bash java -cp target/helidon-examples-grpc-basics.jar \ io.helidon.grpc.examples.basics.HealthClient -``` \ No newline at end of file +``` + +The HealthClient will report a SERVING status for the +first check, and a NOT_FOUND status for a non-existent +service. \ No newline at end of file diff --git a/examples/grpc/basics/src/main/java/io/helidon/grpc/examples/basics/Server.java b/examples/grpc/basics/src/main/java/io/helidon/grpc/examples/basics/Server.java index 9d8f88302..f463be2ca 100644 --- a/examples/grpc/basics/src/main/java/io/helidon/grpc/examples/basics/Server.java +++ b/examples/grpc/basics/src/main/java/io/helidon/grpc/examples/basics/Server.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020 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. @@ -75,8 +75,8 @@ public class Server { // add support for standard and gRPC health checks HealthSupport health = HealthSupport.builder() - .add(HealthChecks.healthChecks()) - .add(grpcServer.healthChecks()) + .addLiveness(HealthChecks.healthChecks()) + .addLiveness(grpcServer.healthChecks()) .build(); // start web server with health endpoint diff --git a/examples/grpc/metrics/README.md b/examples/grpc/metrics/README.md index 449b01ccd..18b9e3fee 100644 --- a/examples/grpc/metrics/README.md +++ b/examples/grpc/metrics/README.md @@ -4,7 +4,6 @@ A basic example using metrics with gRPC server. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-grpc-metrics.jar @@ -13,4 +12,4 @@ java -jar target/helidon-examples-grpc-metrics.jar Try the metrics: ```bash curl http://localhost:8080/metrics -``` \ No newline at end of file +``` diff --git a/examples/grpc/security-abac/README.md b/examples/grpc/security-abac/README.md index 050948ad3..c9486db4a 100644 --- a/examples/grpc/security-abac/README.md +++ b/examples/grpc/security-abac/README.md @@ -4,7 +4,6 @@ An example gRPC server for attribute based access control. ## Build and run -With JDK8+ ```bash mvn -f ../pom.xml -pl common/security-abac package java -jar target/helidon-examples-grpc-security-abac.jar @@ -13,4 +12,4 @@ java -jar target/helidon-examples-grpc-security-abac.jar Take a look at the metrics: ```bash curl http://localhost:8080/metrics -``` \ No newline at end of file +``` diff --git a/examples/grpc/security-outbound/README.md b/examples/grpc/security-outbound/README.md index 4b4662ae7..256c1fc75 100644 --- a/examples/grpc/security-outbound/README.md +++ b/examples/grpc/security-outbound/README.md @@ -4,7 +4,6 @@ An example gRPC outbound security ## Build and run -With JDK8+ ```bash mvn -f ../pom.xml -pl common/security-outbound package java -jar target/helidon-examples-grpc-security-outbound.jar @@ -14,4 +13,4 @@ Exercise the example: ```bash java -cp target/helidon-examples-grpc-security-outbound.jar \ io.helidon.grpc.examples.security.outbound.SecureGreetClient -``` \ No newline at end of file +``` diff --git a/examples/grpc/security/README.md b/examples/grpc/security/README.md index 2e38c72d8..ef29b3d66 100644 --- a/examples/grpc/security/README.md +++ b/examples/grpc/security/README.md @@ -4,7 +4,6 @@ An example gRPC server using basic auth security. ## Build and run -With JDK8+ ```bash mvn -f ../pom.xml -pl common/security package java -jar target/helidon-examples-grpc-security.jar @@ -16,4 +15,4 @@ java -cp target/helidon-examples-grpc-security.jar \ io.helidon.grpc.examples.security.SecureGreetClient java -cp target/helidon-examples-grpc-security.jar \ io.helidon.grpc.examples.security.SecureStringClient -``` \ No newline at end of file +``` diff --git a/examples/health/basics/README.md b/examples/health/basics/README.md index 40e46e3fc..bca6a94a5 100644 --- a/examples/health/basics/README.md +++ b/examples/health/basics/README.md @@ -6,8 +6,18 @@ custom health check. ## Build and run -With JDK8+ +Start the application: + ```bash mvn package java -jar target/helidon-examples-health-basics.jar ``` + +Note the port number reported by the application. + +Probe the health endpoints: + +```bash +curl -X GET http://localhost:PORT/health/ +curl -X GET http://localhost:PORT/health/ready + diff --git a/examples/health/basics/pom.xml b/examples/health/basics/pom.xml index eb6438518..a510664b4 100644 --- a/examples/health/basics/pom.xml +++ b/examples/health/basics/pom.xml @@ -61,4 +61,19 @@ test + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + + diff --git a/examples/health/basics/src/main/java/io/helidon/examples/health/basics/Main.java b/examples/health/basics/src/main/java/io/helidon/examples/health/basics/Main.java index 9e445cc88..06b9e85f8 100644 --- a/examples/health/basics/src/main/java/io/helidon/examples/health/basics/Main.java +++ b/examples/health/basics/src/main/java/io/helidon/examples/health/basics/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 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. @@ -39,8 +39,8 @@ public final class Main { */ public static void main(String[] args) { HealthSupport health = HealthSupport.builder() - .add(HealthChecks.healthChecks()) - .add((HealthCheck) () -> HealthCheckResponse.named("exampleHealthCheck") + .addLiveness(HealthChecks.healthChecks()) + .addReadiness((HealthCheck) () -> HealthCheckResponse.named("exampleHealthCheck") .up() .withData("time", System.currentTimeMillis()) .build()) diff --git a/examples/integrations/cdi/datasource-hikaricp-h2/README.md b/examples/integrations/cdi/datasource-hikaricp-h2/README.md index 647241763..31b6042c9 100644 --- a/examples/integrations/cdi/datasource-hikaricp-h2/README.md +++ b/examples/integrations/cdi/datasource-hikaricp-h2/README.md @@ -8,7 +8,6 @@ database. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-integrations-examples-datasource-hikaricp-h2.jar diff --git a/examples/integrations/cdi/datasource-hikaricp-mysql/README.md b/examples/integrations/cdi/datasource-hikaricp-mysql/README.md index 1a538401c..3c29030a3 100644 --- a/examples/integrations/cdi/datasource-hikaricp-mysql/README.md +++ b/examples/integrations/cdi/datasource-hikaricp-mysql/README.md @@ -40,7 +40,6 @@ javax.sql.DataSource.example.dataSource.password = tiger ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-integrations-examples-datasource-hikaricp-mysql.jar diff --git a/examples/integrations/cdi/datasource-hikaricp/README.md b/examples/integrations/cdi/datasource-hikaricp/README.md index a544ba881..02afbc74a 100644 --- a/examples/integrations/cdi/datasource-hikaricp/README.md +++ b/examples/integrations/cdi/datasource-hikaricp/README.md @@ -67,7 +67,6 @@ docker run --rm -d \ -p 8080:8080 helidon-examples-integrations-datasource-hikaricp:latest ``` -With JDK8+ ```bash mvn package java -jar target/helidon-examples-integrations-datasource-hikaricp.jar @@ -81,4 +80,4 @@ curl http://localhost:8080/tables Stop the docker containers: ```bash docker stop oracle helidon-examples-integrations-datasource-hikaricp -``` \ No newline at end of file +``` diff --git a/examples/integrations/cdi/jedis/README.md b/examples/integrations/cdi/jedis/README.md index 88fb47b76..41c3810f3 100644 --- a/examples/integrations/cdi/jedis/README.md +++ b/examples/integrations/cdi/jedis/README.md @@ -17,7 +17,7 @@ docker run --rm -d \ -p 8080:8080 helidon-examples-integrations-cdi-jedis:latest ``` -With Java 8+: +With Java: ```bash mvn package java -jar target/helidon-examples-integrations-cdi-jedis.jar @@ -50,4 +50,4 @@ docker stop redis helidon-examples-integrations-cdi-jedis Delete the Kubernetes resources: ```bash kubectl delete -f ../../k8s/ingress.yaml -f app.yaml -``` \ No newline at end of file +``` diff --git a/examples/integrations/cdi/jedis/src/main/java/io/helidon/integrations/examples/jedis/jaxrs/Application.java b/examples/integrations/cdi/jedis/src/main/java/io/helidon/integrations/examples/jedis/jaxrs/Application.java deleted file mode 100644 index 93643524e..000000000 --- a/examples/integrations/cdi/jedis/src/main/java/io/helidon/integrations/examples/jedis/jaxrs/Application.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.integrations.examples.jedis.jaxrs; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; - -/** - * A JAX-RS {@link javax.ws.rs.core.Application application} in - * {@linkplain ApplicationScoped application scope}. - * - * @see #getClasses() - */ -@ApplicationScoped -@ApplicationPath("/") -public class Application extends javax.ws.rs.core.Application { - - private final Set> classes; - - /** - * Creates a new {@link Application}. - */ - public Application() { - super(); - final Set> classes = new HashSet<>(); - classes.add(RedisClientResource.class); - this.classes = Collections.unmodifiableSet(classes); - } - - /** - * Returns a non-{@code null} {@linkplain - * java.util.Collections#unmodifiableSet(Set) immutable - * Set} of {@link Class}es that comprise this JAX-RS - * application. - * - * @return a non-{@code null} {@linkplain - * java.util.Collections#unmodifiableSet(Set) immutable - * Set} - */ - @Override - public Set> getClasses() { - return this.classes; - } - -} diff --git a/examples/integrations/cdi/jpa/README.md b/examples/integrations/cdi/jpa/README.md index 6bb4115fa..c505468b4 100644 --- a/examples/integrations/cdi/jpa/README.md +++ b/examples/integrations/cdi/jpa/README.md @@ -1,6 +1,6 @@ # JPA Integration Example -With Java 8+: +With Java: ```bash mvn package java -jar target/helidon-integrations-examples-jpa.jar diff --git a/examples/integrations/cdi/oci-objectstorage/README.md b/examples/integrations/cdi/oci-objectstorage/README.md index 6383ef77c..bc8c45767 100644 --- a/examples/integrations/cdi/oci-objectstorage/README.md +++ b/examples/integrations/cdi/oci-objectstorage/README.md @@ -29,7 +29,7 @@ docker run --rm -d -p 8080:8080 \ helidon-examples-integrations-cdi-oci-objectstorage:latest ``` -With Java 8+: +With Java: ```bash mvn package java -Doci.auth.fingerprint="${OCI_AUTH_FINGERPRINT}" \ @@ -70,4 +70,4 @@ docker stop helidon-examples-integrations-cdi-oci-objectstorage Delete the Kubernetes resources: ```bash kubectl delete -f ../../../k8s/ingress.yaml -f app.yaml -``` \ No newline at end of file +``` diff --git a/examples/integrations/cdi/oci-objectstorage/src/main/java/io/helidon/integrations/examples/oci/objectstorage/jaxrs/Application.java b/examples/integrations/cdi/oci-objectstorage/src/main/java/io/helidon/integrations/examples/oci/objectstorage/jaxrs/Application.java deleted file mode 100644 index 7154f5a66..000000000 --- a/examples/integrations/cdi/oci-objectstorage/src/main/java/io/helidon/integrations/examples/oci/objectstorage/jaxrs/Application.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.integrations.examples.oci.objectstorage.jaxrs; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; - -/** - * A JAX-RS {@linkplain javax.ws.rs.core.Application application} in {@linkplain ApplicationScoped application scope}. - * - * @see #getClasses() - */ -@ApplicationScoped -@ApplicationPath("/") -public class Application extends javax.ws.rs.core.Application { - - private final Set> classes; - - /** - * Creates a new {@link Application}. - */ - public Application() { - super(); - final Set> classes = new HashSet<>(); - classes.add(HelidonLogoResource.class); - this.classes = Collections.unmodifiableSet(classes); - } - - /** - * Returns a non-{@code null} {@linkplain - * java.util.Collections#unmodifiableSet(Set) immutable - * Set} of {@link Class}es that comprise this JAX-RS application. - * - * @return a non-{@code null} {@linkplain - * java.util.Collections#unmodifiableSet(Set) immutable - * Set} - */ - @Override - public Set> getClasses() { - return this.classes; - } - -} diff --git a/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/HelloWorldApplication.java b/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/HelloWorldApplication.java deleted file mode 100644 index e34899486..000000000 --- a/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/HelloWorldApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.microprofile.example.helloworld.explicit; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * - */ -@ApplicationScoped -@ApplicationPath("/") -public class HelloWorldApplication extends Application { - - @Override - public Set> getClasses() { - return Set.of( - HelloWorldResource.class - ); - } -} diff --git a/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/Main.java b/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/Main.java index 77e12c905..ad6d5f38d 100644 --- a/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/Main.java +++ b/examples/microprofile/hello-world-explicit/src/main/java/io/helidon/microprofile/example/helloworld/explicit/Main.java @@ -34,8 +34,7 @@ public class Main { */ public static void main(String[] args) { Server server = Server.builder() - .addApplication(HelloWorldApplication.class) - // using a customized helidon config instance (in this case the default...) + // Provide a MicroProfile config instance (in this case the default...) .config(ConfigProviderResolver.instance() .getBuilder() .build()) diff --git a/examples/microprofile/hello-world-implicit/README.md b/examples/microprofile/hello-world-implicit/README.md index 582629a3a..2409c6fab 100644 --- a/examples/microprofile/hello-world-implicit/README.md +++ b/examples/microprofile/hello-world-implicit/README.md @@ -6,7 +6,6 @@ It is implicit because in this example you don't write the ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-microprofile-hello-world-implicit.jar diff --git a/examples/microprofile/hello-world-implicit/src/main/java/io/helidon/microprofile/example/helloworld/implicit/HelloWorldApplication.java b/examples/microprofile/hello-world-implicit/src/main/java/io/helidon/microprofile/example/helloworld/implicit/HelloWorldApplication.java deleted file mode 100644 index 899b2b630..000000000 --- a/examples/microprofile/hello-world-implicit/src/main/java/io/helidon/microprofile/example/helloworld/implicit/HelloWorldApplication.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.microprofile.example.helloworld.implicit; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * Application for example with two resource classes. - */ -@ApplicationScoped -@ApplicationPath("/") -public class HelloWorldApplication extends Application { - - @Override - public Set> getClasses() { - return Set.of( - HelloWorldResource.class, - AnotherResource.class - ); - } -} diff --git a/examples/microprofile/hello-world-implicit/src/test/java/io/helidon/microprofile/example/helloworld/implicit/ImplicitHelloWorldTest.java b/examples/microprofile/hello-world-implicit/src/test/java/io/helidon/microprofile/example/helloworld/implicit/ImplicitHelloWorldTest.java index b1d81ce02..81fd38ebf 100644 --- a/examples/microprofile/hello-world-implicit/src/test/java/io/helidon/microprofile/example/helloworld/implicit/ImplicitHelloWorldTest.java +++ b/examples/microprofile/hello-world-implicit/src/test/java/io/helidon/microprofile/example/helloworld/implicit/ImplicitHelloWorldTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 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. @@ -23,6 +23,7 @@ import javax.ws.rs.client.ClientBuilder; import io.helidon.microprofile.server.Main; +import io.helidon.microprofile.server.Server; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -35,9 +36,12 @@ import static org.junit.jupiter.api.Assertions.assertAll; * Unit test for {@link HelloWorldResource}. */ class ImplicitHelloWorldTest { + private static Server server; + + @BeforeAll static void initClass() { - Main.main(new String[0]); + server = Server.create().start(); } @AfterAll @@ -49,7 +53,7 @@ class ImplicitHelloWorldTest { @Test void testJsonResource() { JsonObject jsonObject = ClientBuilder.newClient() - .target("http://localhost:" + Main.serverPort() + "/helloworld/unit") + .target("http://localhost:" + server.port() + "/helloworld/unit") .request() .get(JsonObject.class); diff --git a/examples/microprofile/idcs/README.md b/examples/microprofile/idcs/README.md index c8e331f0b..0a1deb9f4 100644 --- a/examples/microprofile/idcs/README.md +++ b/examples/microprofile/idcs/README.md @@ -4,7 +4,6 @@ Example JAX-RS application with resources protected by IDCS ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-microprofile-security-idcs.jar diff --git a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingExampleResource.java b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingExampleResource.java index bf872bd2c..a94620959 100644 --- a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingExampleResource.java +++ b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingExampleResource.java @@ -46,6 +46,10 @@ public class MessagingExampleResource { } + /** + * Process send. + * @param msg message to process + */ @Path("/send/{msg}") @GET @Produces(MediaType.APPLICATION_JSON) @@ -53,6 +57,12 @@ public class MessagingExampleResource { msgBean.process(msg); } + /** + * Consume event. + * + * @param eventSink sink + * @param sse event + */ @GET @Path("sse") @Produces(MediaType.SERVER_SENT_EVENTS) diff --git a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingSseExampleApplication.java b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingSseExampleApplication.java deleted file mode 100644 index f83ac20eb..000000000 --- a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MessagingSseExampleApplication.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 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. - * 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 io.helidon.microprofile.example.messaging.sse; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * Example showing - * Microprofile Reactive Messaging - * with Microprofile Reactive Stream Operators - * connected to Server-Sent Events. - */ -@ApplicationScoped -@ApplicationPath("/") -public class MessagingSseExampleApplication extends Application { - - @Override - public Set> getClasses() { - return Set.of( - MessagingExampleResource.class - ); - } -} diff --git a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MsgProcessingBean.java b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MsgProcessingBean.java index 94862a1c3..a6fc40c70 100644 --- a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MsgProcessingBean.java +++ b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/MsgProcessingBean.java @@ -33,11 +33,19 @@ import org.glassfish.jersey.media.sse.OutboundEvent; import org.reactivestreams.FlowAdapters; import org.reactivestreams.Publisher; +/** + * Bean for message processing. + */ @ApplicationScoped public class MsgProcessingBean { private final SubmissionPublisher emitter = new SubmissionPublisher<>(); private SseBroadcaster sseBroadcaster; + /** + * Create a publisher for the emitter. + * + * @return A Publisher from the emitter + */ @Outgoing("multiplyVariants") public Publisher preparePublisher() { // Create new publisher for emitting to by this::process @@ -46,6 +54,11 @@ public class MsgProcessingBean { .buildRs(); } + /** + * Returns a builder for a processor that maps a string into three variants. + * + * @return ProcessorBuilder + */ @Incoming("multiplyVariants") @Outgoing("wrapSseEvent") public ProcessorBuilder multiply() { @@ -62,6 +75,12 @@ public class MsgProcessingBean { ); } + /** + * Maps a message to an sse event. + * + * @param msg to wrap + * @return an outbound SSE event + */ @Incoming("wrapSseEvent") @Outgoing("broadcast") public OutboundSseEvent wrapSseEvent(String msg) { @@ -69,12 +88,23 @@ public class MsgProcessingBean { return new OutboundEvent.Builder().data(msg).build(); } + /** + * Broadcasts an event. + * + * @param sseEvent Event to broadcast + */ @Incoming("broadcast") public void broadcast(OutboundSseEvent sseEvent) { // Broadcast to all sse sinks this.sseBroadcaster.broadcast(sseEvent); } + /** + * Consumes events. + * + * @param eventSink event sink + * @param sse event + */ public void addSink(final SseEventSink eventSink, final Sse sse) { if (this.sseBroadcaster == null) { this.sseBroadcaster = sse.newBroadcaster(); @@ -82,6 +112,11 @@ public class MsgProcessingBean { this.sseBroadcaster.register(eventSink); } + /** + * Emit a message. + * + * @param msg message to emit + */ public void process(final String msg) { emitter.submit(msg); } diff --git a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/Main.java b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/package-info.java similarity index 66% rename from examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/Main.java rename to examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/package-info.java index 518223eda..8cee458fb 100644 --- a/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/Main.java +++ b/examples/microprofile/messaging-sse/src/main/java/io/helidon/microprofile/example/messaging/sse/package-info.java @@ -14,23 +14,8 @@ * limitations under the License. */ +/** + * Helidon MicroProfile Messaging Example. + */ package io.helidon.microprofile.example.messaging.sse; -import io.helidon.microprofile.server.Server; - -/** - * Explicit example. - */ -public class Main { - private Main() { - } - - /** - * Starts server and initializes CDI container manually. - * - * @param args command line arguments (ignored) - */ - public static void main(String[] args) { - Server.create().start(); - } -} diff --git a/examples/microprofile/mp1_1-security/README.md b/examples/microprofile/mp1_1-security/README.md index 0a43e9fc8..5ca389935 100644 --- a/examples/microprofile/mp1_1-security/README.md +++ b/examples/microprofile/mp1_1-security/README.md @@ -9,7 +9,6 @@ levels of security. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-microprofile-mp1_1-security.jar diff --git a/examples/microprofile/mp1_1-static-content/README.md b/examples/microprofile/mp1_1-static-content/README.md index 4d10eadce..0209a9686 100644 --- a/examples/microprofile/mp1_1-static-content/README.md +++ b/examples/microprofile/mp1_1-static-content/README.md @@ -7,7 +7,6 @@ The configuration for the static content is in the ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-microprofile-mp1_1-static-content.jar diff --git a/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/Main.java b/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/Main.java index ab1659245..cacb5c04b 100644 --- a/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/Main.java +++ b/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 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. @@ -39,7 +39,7 @@ public class Main { long now = System.nanoTime(); // everything is configured through application.yaml - Server server = Server.create(StaticContentApp.class); + Server server = Server.create(); now = System.nanoTime() - now; System.out.println("Create server: " + TimeUnit.MILLISECONDS.convert(now, TimeUnit.NANOSECONDS)); diff --git a/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/StaticContentApp.java b/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/StaticContentApp.java deleted file mode 100644 index 16c3dab50..000000000 --- a/examples/microprofile/mp1_1-static-content/src/main/java/io/helidon/microprofile/example/staticc/StaticContentApp.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.microprofile.example.staticc; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * Example JAX-RS application with static content. - */ -@ApplicationScoped -@ApplicationPath("/") -public class StaticContentApp extends Application { - @Override - public Set> getClasses() { - return Set.of( - HelloWorldResource.class - ); - } -} diff --git a/examples/microprofile/oidc/README.md b/examples/microprofile/oidc/README.md index ae08d1459..80f82b7f5 100644 --- a/examples/microprofile/oidc/README.md +++ b/examples/microprofile/oidc/README.md @@ -21,8 +21,7 @@ in `application.yaml`. ## Build and run -With JDK8+ ```bash mvn package -java -jar target/helidon-examples-security-oidc-login.jar -``` \ No newline at end of file +java -jar target/helidon-examples-microprofile-security-oidc-login.jar +``` diff --git a/examples/microprofile/oidc/src/main/java/io/helidon/examples/microprofile/security/oidc/OidcTestApplication.java b/examples/microprofile/oidc/src/main/java/io/helidon/examples/microprofile/security/oidc/OidcTestApplication.java deleted file mode 100644 index d380e254d..000000000 --- a/examples/microprofile/oidc/src/main/java/io/helidon/examples/microprofile/security/oidc/OidcTestApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.examples.microprofile.security.oidc; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * A simple JAX-rs application that just returns the single {@link OidcResource resource}. - */ -@ApplicationScoped -@ApplicationPath("/") -public class OidcTestApplication extends Application { - - @Override - public Set> getClasses() { - return Set.of(OidcResource.class); - } -} diff --git a/examples/microprofile/openapi-basic/README.md b/examples/microprofile/openapi-basic/README.md index 0848171f3..b44070fce 100644 --- a/examples/microprofile/openapi-basic/README.md +++ b/examples/microprofile/openapi-basic/README.md @@ -5,7 +5,6 @@ Helidon MP QuickStart, enhanced with OpenAPI support. ## Build and run -With JDK8+ ```bash mvn package java -jar target/helidon-examples-microprofile-openapi-basic.jar diff --git a/examples/microprofile/openapi-basic/src/main/java/io/helidon/microprofile/examples/openapi/basic/GreetApplication.java b/examples/microprofile/openapi-basic/src/main/java/io/helidon/microprofile/examples/openapi/basic/GreetApplication.java deleted file mode 100644 index bb3a8037a..000000000 --- a/examples/microprofile/openapi-basic/src/main/java/io/helidon/microprofile/examples/openapi/basic/GreetApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. - * - * Licensed 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 io.helidon.microprofile.examples.openapi.basic; - -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -/** - * Simple Application that produces a greeting message. - */ -@ApplicationScoped -@ApplicationPath("/") -public class GreetApplication extends Application { - - @Override - public Set> getClasses() { - return Set.of(GreetResource.class); - } -} diff --git a/examples/microprofile/pom.xml b/examples/microprofile/pom.xml index 0e47a4018..fb93dfd72 100644 --- a/examples/microprofile/pom.xml +++ b/examples/microprofile/pom.xml @@ -1,7 +1,7 @@