What you will learn
You will take an existing sample Thorntail application and modify it to address microservice concerns, understand its structure, deploy it to OpenShift and exercise the interfaces between Thorntail apps, microservices, and OpenShift/Kubernetes.
What is Thorntail?
Java EE applications are traditionally created as an ear or war archive including all dependencies and deployed in an application server. Multiple Java EE applications can and were typically deployed in the same application server. This model is well understood in the development teams and has been used over the past several years.
Thorntail offers an innovative approach to packaging and running Java EE applications by packaging them with just enough of the Java EE server runtime to be able to run them directly on the JVM using java -jar For more details on various approaches to packaging Java applications, read this blog post.
Thorntail implements Eclipse MicroProfile, which is a community-driven open source specification that optimizes Enterprise Java for a microservices architecture and delivers application portability across multiple MicroProfile runtimes.
Since Thorntail also draws many of its features from Java EE standards, it significantly simplifies refactoring existing Java EE applications to microservices and allows much of existing codebase to be reused in the new services.
In this scenario you learned a bit more about what Thorntail is, how it implements the MicroProfile specification, and how it can be used to create modern Java microservice-oriented applications.
You took an existing application and developed a new health check for it using Thorntail and MicroProfile, and deployed the application to OpenShift and tested it.
Thorntail brings in a number of concepts and APIs from the Java EE community, so your existing Java EE skills can be re-used to bring your applications into the modern world of containers, microservices and cloud deployments.
Thorntail is one of many components of Red Hat OpenShift Application Runtimes - check out other scenarios (for example the Vert.x scenario) to learn about other runtimes you can use.
Getting Started with Thorntail on OpenShift
Examine the sample project
The sample project shows the components of a Thorntail project laid out in different subdirectories according to Maven best practices.
1. Run the following command to examine the Maven project structure.
Click on the
treecommand below to automatically copy it into the terminal and execute it
This is a minimal Java EE project which implements a simple RESTful microservice which implements a greeting service (that simply returns a Hello greeting). Click the links below to open each file and inspect its contents:
pom.xml- Maven project file describing how to build the project
src/main/java/com/example/ApplicationConfig.java- Declares the RESTful resource base path and a simple switch to toggle the application's ability to serve requests
src/main/java/com/example/Greeting.java- POJO containing a message to send as a greeting
src/main/java/com/example/GreetingResource.java- Definition of the
Review the content a bit and notice that there are some comments in the code. Do not remove them! The comments are used as marker and without them you will not be able finish the scenario.
/greeting API returns a simple message. The
/stop API will simulate the application failing. In a real application
this could happen if the application was overloaded, or a bug in the code causes the application to hang or otherwise not be
able to service requests. For our sample app, we use a simple boolean flag to simulate failure and will toggle this on and off
later to simulate failure.
2. Compile and run the application
Before we add code to the project you should build and test that current application starts as it should.
Since this is already a working application you can already without any code changes run the application locally directly from
thorntail:run as the goal
Since this is the first time we run maven may have to pull down some dependencies (we have tried to prepopulate most for you), but subsequent runs should go really fast.
At this stage the application doesn't really do anything but after a while you will see:
INFO ... THORN99999: Thorntail is Ready
3. Test the application
To begin, click on the Local Web Browser tab in the console frame of this browser window. This will open another tab or window of your browser pointing to port 8080 on your client.
or use this link.
You should now see a html page that looks like this
4. Stop the application
Before moving on, click in the terminal window and then press CTRL-C to stop the running application!
You should see this:
INFO ... THORN0027: Shutdown requested
This indicates the application is stopped.
You have now successfully executed the first step in this scenario.
Now you've seen how you with a few lines of code one can create a simple RESTful HTTP Server capable of serving static content using Thorntail.
In next step of this scenario we will deploy our application to OpenShift Container Platform.