From 6bc712cc4b3a31bb80c8f806ea0c6e1bc7b99b5b Mon Sep 17 00:00:00 2001 From: ashiot Date: Fri, 13 Sep 2024 17:10:16 +0530 Subject: [PATCH] [WFLY-19618] Helloworld REST Quickstart Issue: https://issues.redhat.com/browse/WFLY-19618 --- .../workflows/quickstart_helloworld-rs_ci.yml | 14 ++ README-source.adoc | 1 + helloworld-rs/README-source.adoc | 51 ++++ helloworld-rs/charts/helm.yaml | 6 + helloworld-rs/pom.xml | 219 ++++++++++++++++++ .../helloworld/rest/HelloWorld.java | 27 +++ .../helloworld/rest/JakartaRESTActivator.java | 18 ++ helloworld-rs/src/main/webapp/index.html | 10 + .../helloworld/rest/RESTEndPointIT.java | 54 +++++ pom.xml | 2 +- 10 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/quickstart_helloworld-rs_ci.yml create mode 100644 helloworld-rs/README-source.adoc create mode 100644 helloworld-rs/charts/helm.yaml create mode 100644 helloworld-rs/pom.xml create mode 100644 helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/HelloWorld.java create mode 100644 helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/JakartaRESTActivator.java create mode 100644 helloworld-rs/src/main/webapp/index.html create mode 100644 helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworld/rest/RESTEndPointIT.java diff --git a/.github/workflows/quickstart_helloworld-rs_ci.yml b/.github/workflows/quickstart_helloworld-rs_ci.yml new file mode 100644 index 0000000000..e59808d30a --- /dev/null +++ b/.github/workflows/quickstart_helloworld-rs_ci.yml @@ -0,0 +1,14 @@ +name: WildFly helloworld-rs Quickstart CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - 'helloworld-rs/**' + - '.github/workflows/quickstart_ci.yml' +jobs: + call-quickstart_ci: + uses: ./.github/workflows/quickstart_ci.yml + with: + QUICKSTART_PATH: helloworld-rs + TEST_PROVISIONED_SERVER: true \ No newline at end of file diff --git a/README-source.adoc b/README-source.adoc index 18f6c318fc..e4af630904 100644 --- a/README-source.adoc +++ b/README-source.adoc @@ -136,6 +136,7 @@ NOTE: Some of these quickstarts use the H2 database included with {productNameFu | link:helloworld-mdb/README{outfilesuffix}[helloworld-mdb]|JMS, EJB, MDB | Yes | The `helloworld-mdb` quickstart uses JMS and EJB Message-Driven Bean (MDB) to create and deploy JMS topic and queue resources in {productName}. | Intermediate | _none_ | link:helloworld-mutual-ssl/README{outfilesuffix}[helloworld-mutual-ssl]|Mutual TLS, Undertow | No | The `helloworld-mutual-ssl` quickstart is a basic example that demonstrates mutual TLS configuration in {productName} | Intermediate | _none_ | link:helloworld-mutual-ssl-secured/README{outfilesuffix}[helloworld-mutual-ssl-secured]|Mutual TLS, Security, Undertow | No | The `helloworld-mutual-ssl-secured` quickstart demonstrates securing a Web application using client certificate authentication with authorization | Intermediate | _none_ +| link:helloworld-rs/README{outfilesuffix}[helloworld-rs]|Jakarta RESTful Web Services | No | The `helloworld-rs` quickstart demonstrates the use of Jakarta RESTful Web Services. | Begginer | _none_ | link:helloworld-singleton/README{outfilesuffix}[helloworld-singleton]|EJB, Singleton | Yes | The `helloworld-singleton` quickstart demonstrates an EJB Singleton Bean that is instantiated once and maintains state for the life of the session. | Beginner | _none_ | link:helloworld-ws/README{outfilesuffix}[helloworld-ws]|JAX-WS | Yes | The `helloworld-ws` quickstart demonstrates a simple Hello World application, bundled and deployed as a WAR, that uses JAX-WS to say Hello. | Beginner | _none_ | link:hibernate/README{outfilesuffix}[hibernate]|Hibernate | Yes | The `hibernate` quickstart demonstrates how to use Hibernate ORM 6 over Persistence, using Bean Validation, and Enterprise Beans. | Intermediate | _none_ diff --git a/helloworld-rs/README-source.adoc b/helloworld-rs/README-source.adoc new file mode 100644 index 0000000000..6f3ea5de51 --- /dev/null +++ b/helloworld-rs/README-source.adoc @@ -0,0 +1,51 @@ +include::../shared-doc/attributes.adoc[] + += helloworld-rs: Jakarta RESTful Web Services Helloworld Example +:author: Ashwin Mehendale +:level: Beginner +:technologies: Jakarta RESTful Web Services +:openshift: true +:portedToGlow: true + +[abstract] +The `helloworld-rs` quickstart demonstrates the use of Jakarta RESTful Web Services. + +:standalone-server-type: default +:archiveType: war + +== What is it? + +The `helloworld-rs` quickstart demonstrates the use of _Jakarta RESTful Web Services_ in {productNameFull} {productVersion}. + +// Link to the quickstart source +include::../shared-doc/view-the-source.adoc[leveloffset=+1] +// System Requirements +include::../shared-doc/system-requirements.adoc[leveloffset=+1] +// Use of {jbossHomeName} +include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1] + +// build and run with standard server distribution +[[build_and_run_the_quickstart_with_server_dist]] +== Building and running the quickstart application with a {productName} server distribution +// Start the {productName} Standalone Server +include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+2] +// Build and Deploy the Quickstart +include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+2] + +=== Access the Application +The application will be running at the following URL: http://localhost:8080/{artifactId}/. + +// Server Distribution Testing +include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+2] +// Undeploy the Quickstart +include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+2] + +// Build and run sections for other environments/builds +ifndef::ProductRelease,EAPXPRelease[] +include::../shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc[leveloffset=+1] +endif::[] +include::../shared-doc/build-and-run-the-quickstart-with-openshift.adoc[leveloffset=+1] +ifndef::ProductRelease,EAPXPRelease[] +//Kubernetes +include::../shared-doc/build-and-run-the-quickstart-with-kubernetes.adoc[leveloffset=+1] +endif::[] \ No newline at end of file diff --git a/helloworld-rs/charts/helm.yaml b/helloworld-rs/charts/helm.yaml new file mode 100644 index 0000000000..b8d1283063 --- /dev/null +++ b/helloworld-rs/charts/helm.yaml @@ -0,0 +1,6 @@ +build: + uri: https://github.com/wildfly/quickstart.git + ref: main + contextDir: helloworld-rs +deploy: + replicas: 1 \ No newline at end of file diff --git a/helloworld-rs/pom.xml b/helloworld-rs/pom.xml new file mode 100644 index 0000000000..6d8d58a8bd --- /dev/null +++ b/helloworld-rs/pom.xml @@ -0,0 +1,219 @@ + + + + 4.0.0 + + org.wildfly.quickstarts + wildfly-quickstart-parent + + 8 + + + helloworld-rs + 35.0.0.Beta1-SNAPSHOT + war + Quickstart: helloworld-rs + A simple Hello World project that uses Jakarta RESTful Web Services + + + + Apache License, Version 2.0 + repo + http://www.apache.org/licenses/LICENSE-2.0.html + + + + + + 34.0.0.Final + + ${version.server} + 5.0.0.Final + + + + + + + org.wildfly.bom + wildfly-ee-with-tools + ${version.bom.ee} + pom + import + + + + + + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + + + junit + junit + test + + + org.jboss.resteasy + resteasy-client + test + + + + org.jboss.logging + commons-logging-jboss-logging + test + + + org.jboss.resteasy + resteasy-json-p-provider + test + + + + org.eclipse.parsson + parsson + test + + + + + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.plugin.wildfly} + + + + + + + + provisioned-server + + + + org.wildfly.plugins + wildfly-maven-plugin + + + ${version.server} + + + ROOT.war + + + + + package + + + + + + + + + openshift + + + + org.wildfly.plugins + wildfly-maven-plugin + + + ${version.server} + cloud + + + ROOT.war + + + + + package + + + + + + + + + integration-testing + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/RESTEndPointIT + + + + + + integration-test + verify + + + + + + + + + + + + jboss-public-maven-repository + JBoss Public Maven Repository + https://repository.jboss.org/nexus/content/groups/public/ + + true + never + + + true + never + + default + + + + + jboss-public-maven-repository + JBoss Public Maven Repository + https://repository.jboss.org/nexus/content/groups/public/ + + true + + + true + + + + diff --git a/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/HelloWorld.java b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/HelloWorld.java new file mode 100644 index 0000000000..5803dda403 --- /dev/null +++ b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/HelloWorld.java @@ -0,0 +1,27 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.quickstarts.helloworld.rest; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +/** + * A simple REST service which is able to say "Hello World!" + * + * @author Ashwin Mehendale + * @author emartins + */ + +@Path("/") +public class HelloWorld { + + @GET + @Path("/HelloWorld") + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "Hello World!"; + } +} diff --git a/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/JakartaRESTActivator.java b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/JakartaRESTActivator.java new file mode 100644 index 0000000000..d515d9fb4a --- /dev/null +++ b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworld/rest/JakartaRESTActivator.java @@ -0,0 +1,18 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.quickstarts.helloworld.rest; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +/** + * JakartaRESTActivator is an arbitrary name, what is important is that jakarta.ws.rs.core.Application is extended + * and the @ApplicationPath annotation is used with a "rest" path. Without this the rest endpoints linked to + * from index.html would not be found. + */ +@ApplicationPath("rest") +public class JakartaRESTActivator extends Application { + // Left empty intentionally +} \ No newline at end of file diff --git a/helloworld-rs/src/main/webapp/index.html b/helloworld-rs/src/main/webapp/index.html new file mode 100644 index 0000000000..d6d29631a2 --- /dev/null +++ b/helloworld-rs/src/main/webapp/index.html @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworld/rest/RESTEndPointIT.java b/helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworld/rest/RESTEndPointIT.java new file mode 100644 index 0000000000..b151eaac9b --- /dev/null +++ b/helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworld/rest/RESTEndPointIT.java @@ -0,0 +1,54 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.quickstarts.helloworld.rest; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * The very basic runtime integration testing for a rest endpoint. + * @author Ashwin Mehendale + * @author emartins + */ +public class RESTEndPointIT { + private Client client; + private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/helloworld-rs"; + + private static String getServerHost() { + String serverHost = System.getenv("SERVER_HOST"); + if (serverHost == null) { + serverHost = System.getProperty("server.host"); + } + if (serverHost == null) { + serverHost = DEFAULT_SERVER_HOST; + } + return serverHost; + } + + @Before + public void before() { + client = ClientBuilder.newClient(); + } + + @After + public void after() { + client.close(); + } + + @Test + public void testRestEndPoint() { + WebTarget target = client.target(getServerHost()) + .path("/rest/HelloWorld"); + String responseMessage = target.request(MediaType.TEXT_PLAIN).get(String.class); + assertEquals("Hello World!", responseMessage); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2d153290a..5b9ee5c381 100644 --- a/pom.xml +++ b/pom.xml @@ -255,6 +255,7 @@ helloworld-mdb helloworld-mutual-ssl helloworld-mutual-ssl-secured + helloworld-rs helloworld-singleton helloworld-ws hibernate @@ -445,7 +446,6 @@ - jboss-public-maven-repository