From be6db34b379e564c74c11f77db4d80e4b844b7bd Mon Sep 17 00:00:00 2001 From: Ravi Srinivasan Date: Tue, 4 Jun 2019 12:44:55 +0530 Subject: [PATCH] refactored hello-java app to use thorntail --- hello-java/Dockerfile | 2 +- hello-java/app-src/pom.xml | 85 +++++++------------ .../openshift/hello/HelloResource.java | 14 +-- .../redhat/training/openshift/hello/Main.java | 31 ------- .../src/main/resources/WEB-INF/beans.xml | 5 -- .../src/main/resources/WEB-INF/web.xml | 6 -- hello-java/run-app.sh | 4 +- 7 files changed, 44 insertions(+), 103 deletions(-) delete mode 100644 hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/Main.java delete mode 100644 hello-java/app-src/src/main/resources/WEB-INF/beans.xml delete mode 100644 hello-java/app-src/src/main/resources/WEB-INF/web.xml diff --git a/hello-java/Dockerfile b/hello-java/Dockerfile index a692ec72bc..f8b16e4fcc 100644 --- a/hello-java/Dockerfile +++ b/hello-java/Dockerfile @@ -13,7 +13,7 @@ RUN yum install -y --disableplugin=subscription-manager java-1.8.0-openjdk-hea mkdir -p /opt/app-root/bin # Copy the runnable fat JAR to the container. -ADD https://github.com/RedHatTraining/DO288-apps/releases/download/1.0/hello-swarm.jar /opt/app-root/bin/ +ADD https://github.com/RedHatTraining/DO288-apps/releases/download/OCP-4.1-1/hello-java.jar /opt/app-root/bin/ COPY run-app.sh /opt/app-root/bin/ diff --git a/hello-java/app-src/pom.xml b/hello-java/app-src/pom.xml index 33d2a2828a..c4d809fb9f 100644 --- a/hello-java/app-src/pom.xml +++ b/hello-java/app-src/pom.xml @@ -5,11 +5,11 @@ 4.0.0 com.redhat.training.openshift - hello-swarm + hello-java 1.0 war - Red Hat Training ToT app - Hello microservice using WildFly Swarm + Red Hat Training Hello Java app + Hello microservice using Thorntail UTF-8 + false - - 2017.10.0 + + 2.4.0.Final 3.1 @@ -34,33 +35,25 @@ - - - - org.wildfly.swarm - bom - ${version.wildfly.swarm} - pom - import - - - + + + io.thorntail + bom-all + ${version.thorntail} + import + pom + + + - org.wildfly.swarm - jaxrs-jsonp - - - org.wildfly.swarm - jaxrs-cdi + io.thorntail + cdi - org.wildfly.swarm - cdi + io.thorntail + jaxrs @@ -70,33 +63,21 @@ given to the generated war, and hence the context root) --> hello + + - maven-war-plugin - ${version.war.plugin} - - - false - - - - - - org.wildfly.swarm - wildfly-swarm-plugin - ${version.wildfly.swarm} - - com.redhat.training.openshift.hello.Main - - - - - package - - - - + io.thorntail + thorntail-maven-plugin + ${version.thorntail} + + + + package + + + + - diff --git a/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/HelloResource.java b/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/HelloResource.java index 91c7fe3eb3..b9555e17f1 100644 --- a/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/HelloResource.java +++ b/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/HelloResource.java @@ -13,12 +13,14 @@ public class HelloResource { @Produces("text/plain") public String hello() { String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown"); - String message = System.getenv().getOrDefault("APP_MSG", null); - String response = ""; - if (message == null) - response = "Hello world from host "+hostname+"\n"; - else - response = "Hello world from host ["+hostname+"]. Message received = "+message+"\n"; + String message = System.getenv().getOrDefault("APP_MSG", null); + String response = ""; + + if (message == null) + response = "Hello world from host "+hostname+"\n"; + else + response = "Hello world from host ["+hostname+"]. Message received = "+message+"\n"; + return response; } } diff --git a/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/Main.java b/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/Main.java deleted file mode 100644 index 0be709d743..0000000000 --- a/hello-java/app-src/src/main/java/com/redhat/training/openshift/hello/Main.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.redhat.training.openshift.hello; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; -import org.wildfly.swarm.Swarm; -import org.wildfly.swarm.undertow.WARArchive; - -public class Main { - - public static void main(String[] args) throws Exception { - // Instantiate the container - Swarm swarm = new Swarm(args); - - // Create one or more deployments - WARArchive deployment = ShrinkWrap.create(WARArchive.class); - - // Add resource to deployment - deployment.addPackage(Main.class.getPackage()); - deployment.addAllDependencies(); - - // Add Web resources - deployment.addAsWebInfResource( - new ClassLoaderAsset("WEB-INF/web.xml", Main.class.getClassLoader()), "web.xml"); - deployment.addAsWebInfResource( - new ClassLoaderAsset("WEB-INF/beans.xml", Main.class.getClassLoader()), "beans.xml"); - - swarm.start().deploy(deployment); - - } - -} diff --git a/hello-java/app-src/src/main/resources/WEB-INF/beans.xml b/hello-java/app-src/src/main/resources/WEB-INF/beans.xml deleted file mode 100644 index 1724d41bb4..0000000000 --- a/hello-java/app-src/src/main/resources/WEB-INF/beans.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/hello-java/app-src/src/main/resources/WEB-INF/web.xml b/hello-java/app-src/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index 77716b63e4..0000000000 --- a/hello-java/app-src/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/hello-java/run-app.sh b/hello-java/run-app.sh index 73c9e8947c..c5f346a5d9 100755 --- a/hello-java/run-app.sh +++ b/hello-java/run-app.sh @@ -1,7 +1,7 @@ #!/bin/sh -echo "Starting wildfly swarm app..." +echo "Starting hello-java app..." echo "JVM options => $JAVA_OPTIONS" echo -java $JAVA_OPTIONS -jar /opt/app-root/bin/hello-swarm.jar +java $JAVA_OPTIONS -jar /opt/app-root/bin/hello-java.jar