From 1dc1e7e1dd3fcfdf784c0bb62c330bc32c54b84d Mon Sep 17 00:00:00 2001
From: Dan K <dk14142@gmail.com>
Date: Fri, 19 Jul 2019 16:02:04 +0200
Subject: [PATCH] Merge branch 'dkolepp/ch9s6' feat(ch9s6): add micro-java project

---
 micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java |    8 ++
 micro-java/pom.xml                                                               |   96 ++++++++++++++++++++++++++++++++
 micro-java/src/main/fabric8/cm.yml                                               |    7 ++
 micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java  |   27 +++++++++
 micro-java/src/main/fabric8/deployment.yml                                       |   11 +++
 5 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/micro-java/pom.xml b/micro-java/pom.xml
new file mode 100644
index 0000000..9c8b9cd
--- /dev/null
+++ b/micro-java/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>com.redhat.training.openshift</groupId>
+  <artifactId>hello</artifactId>
+  <version>1.0</version>
+  <packaging>war</packaging>
+  <name>Red Hat Training Hello Java app</name>
+  <description>Hello microservice using Thorntail</description>
+
+  <properties>
+    <!-- Explicitly declaring the source encoding eliminates the following
+      message: -->
+    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+      resources, i.e. build is platform dependent! -->
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <failOnMissingWebXml>false</failOnMissingWebXml>
+
+    <!-- Thorntail dependency versions -->
+    <version.thorntail>2.4.0.Final</version.thorntail>
+
+    <!-- other plugin versions -->
+    <version.compiler.plugin>3.1</version.compiler.plugin>
+    <version.surefire.plugin>2.16</version.surefire.plugin>
+    <version.war.plugin>2.5</version.war.plugin>
+    <version.fabric8.plugin>4.1.0</version.fabric8.plugin>
+
+    <!-- maven-compiler-plugin -->
+    <maven.compiler.target>1.8</maven.compiler.target>
+    <maven.compiler.source>1.8</maven.compiler.source>
+  </properties>
+
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>io.thorntail</groupId>
+        <artifactId>bom-all</artifactId>
+        <version>${version.thorntail}</version>
+        <scope>import</scope>
+        <type>pom</type>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>io.thorntail</groupId>
+      <artifactId>cdi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.thorntail</groupId>
+      <artifactId>jaxrs</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <!-- Maven will append the version to the finalName (which is the name
+         given to the generated war, and hence the context root) -->
+    <finalName>hello</finalName>
+    <plugins>
+      <!-- The Thorntail Maven plugin creates an uber jar -->
+      <!-- To use, run: mvn thorntail:run -->
+      <plugin>
+        <groupId>io.thorntail</groupId>
+        <artifactId>thorntail-maven-plugin</artifactId>
+        <version>${version.thorntail}</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>package</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>io.fabric8</groupId>
+        <artifactId>fabric8-maven-plugin</artifactId>
+        <version>${version.fabric8.plugin}</version>
+        <executions>
+          <execution>
+            <id>fmp</id>
+            <goals>
+              <goal>resource</goal>
+              <goal>build</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/micro-java/src/main/fabric8/cm.yml b/micro-java/src/main/fabric8/cm.yml
new file mode 100644
index 0000000..a6763d0
--- /dev/null
+++ b/micro-java/src/main/fabric8/cm.yml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: env-config 
+data:
+  APP_MSG:
+ 
diff --git a/micro-java/src/main/fabric8/deployment.yml b/micro-java/src/main/fabric8/deployment.yml
new file mode 100644
index 0000000..941530b
--- /dev/null
+++ b/micro-java/src/main/fabric8/deployment.yml
@@ -0,0 +1,11 @@
+
+
+spec:
+  template:
+    spec:
+      containers:
+        - envFrom:
+            - configMapRef:
+                name: env-config
+
+
diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java
new file mode 100644
index 0000000..7b39d65
--- /dev/null
+++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java
@@ -0,0 +1,27 @@
+package com.redhat.training.openshift.hello;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+@Path("/")
+public class HelloResource {
+
+    @GET
+    @Path("/hello")
+    @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+"].";
+      	  response += "Message received = "+message+"\n";
+        }
+        return response;
+    }
+}
diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java
new file mode 100644
index 0000000..7a6a14a
--- /dev/null
+++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java
@@ -0,0 +1,8 @@
+package com.redhat.training.openshift.hello;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/api")
+public class JaxRsActivator extends Application {
+}

--
Gitblit v1.9.3