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..2c6a80a791 --- /dev/null +++ b/helloworld-rs/pom.xml @@ -0,0 +1,221 @@ + + + + 4.0.0 + + org.wildfly.quickstarts + wildfly-quickstart-parent + + 8 + + + helloworld-rs + 34.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 + + + + + + 33.0.0.Final + + ${version.server} + 5.0.0.Final + + + + + jboss-public-maven-repository + JBoss Public Maven Repository + https://repository.jboss.org/nexus/content/groups/public/ + + true + never + + + true + never + + default + + + redhat-ga-maven-repository + Red Hat GA Maven Repository + https://maven.repository.redhat.com/ga/ + + true + never + + + true + never + + default + + + + + jboss-public-maven-repository + JBoss Public Maven Repository + https://repository.jboss.org/nexus/content/groups/public/ + + true + + + true + + + + redhat-ga-maven-repository + Red Hat GA Maven Repository + https://maven.repository.redhat.com/ga/ + + true + + + true + + + + + + + + + org.wildfly.bom + wildfly-ee-with-tools + ${version.bom.ee} + pom + import + + + + + + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + + + junit + junit + 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 + + + **/BasicRuntimeIT + + + + + + integration-test + verify + + + + + + + + + + diff --git a/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/HelloWorld.java b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/HelloWorld.java new file mode 100644 index 0000000000..2ec8f8751b --- /dev/null +++ b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/HelloWorld.java @@ -0,0 +1,27 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.quickstarts.rshelloworld; + +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 getHelloWorld() { + return "Hello World!"; + } +} diff --git a/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/JakartaRESTActivator.java b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/JakartaRESTActivator.java new file mode 100644 index 0000000000..a107449aad --- /dev/null +++ b/helloworld-rs/src/main/java/org/jboss/as/quickstarts/helloworldrs/JakartaRESTActivator.java @@ -0,0 +1,18 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.quickstarts.rshelloworld; + +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/helloworldrs/BasicRuntimeIT.java b/helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworldrs/BasicRuntimeIT.java new file mode 100644 index 0000000000..da0d69653d --- /dev/null +++ b/helloworld-rs/src/test/java/org/jboss/as/quickstarts/helloworldrs/BasicRuntimeIT.java @@ -0,0 +1,70 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.quickstarts.helloworld; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +/** + * The very basic runtime integration testing. + * @author Ashwin Mehendale + * @author emartins + */ +public class BasicRuntimeIT { + + private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/helloworld-rs"; + + private static String getServerHost() throws IOException, InterruptedException, URISyntaxException{ + String serverHost = System.getenv("SERVER_HOST"); + if (serverHost == null) { + serverHost = System.getProperty("server.host"); + } + if (serverHost == null) { + serverHost = DEFAULT_SERVER_HOST; + } + return serverHost; + } + + @Test + public void testHTTPEndpointIsAvailable() throws IOException, InterruptedException, URISyntaxException { + String serverHost = this.getServerHost(); + final HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(serverHost)) + .GET() + .build(); + final HttpClient client = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) + .connectTimeout(Duration.ofMinutes(1)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assertEquals(200, response.statusCode()); + } + + @Test + public void testMessage() throws IOException, InterruptedException, URISyntaxException { + String serverHost = this.getServerHost(); + final HttpRequest request = HttpRequest.newBuilder() + .uri(new URI(serverHost+"/rest/HelloWorld")) + .GET() + .build(); + final HttpClient client = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) + .connectTimeout(Duration.ofMinutes(1)) + .build(); + final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello World!")); + } + + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index fd2b0b02d6..28ac980004 100644 --- a/pom.xml +++ b/pom.xml @@ -310,6 +310,7 @@ helloworld-mdb helloworld-mutual-ssl helloworld-mutual-ssl-secured + helloworld-rs helloworld-singleton helloworld-ws hibernate @@ -500,4 +501,4 @@ - + \ No newline at end of file