Build & Deploy a Jetty based app using Oracle Cloud

Abhishek Gupta
Oracle Developers
Published in
4 min readAug 1, 2017

--

This blog demonstrates the following

Jetty ?

For those who are not familiar with Jetty, it is fundamentally,

  • A Web (HTTP) server, and
  • A Servlet compliant container

Additionally, one can use it to carve out a custom container since it’s modular nature allows you to plug-in implementations for most of the Java EE Web Profile specifications (e.g. Websocket, CDI, JPA etc.). Details in the documentation

About the sample application

The application is similar to what I had used in a previous blog — keeps track of stock prices of NYSE scrips and exposes them using REST & Websocket endpoints

The important difference is that in this example stock prices are not tracked & broadcasted using EJB + CDI events combo — instead, a (plain Java SE based)ScheduledExecutorService is used, which

  • uses a background task thread (Runnable) to fetch the price at regular intervals, and
  • sends them to each of the connected Websocket clients

The application is available here. Lets explore some of its specific areas

Setting up required containers/runtimes

Let’s look at how Jetty is used to provide REST as well as Websocket based functionality

  • JAX-RS container: This application leverages the pluggable Jetty (Servlet) module for Jersey i.e. Jetty Servlet container serves as a runtime for the Jersey (JAX-RS) implementation
  • Websocket container: Jetty provides a first class implementation for the Java Websocket API (JSR 356) — thus, its possible leverage that without having to plugin any other implementation (e.g. Tyrus)

Here is a snippet from the pom.xml which shows the required dependencies

Excerpt from the pom.xml

Bootstrapping respective containers

Bootstrap JAX-RS and Websocket runtimes

Websocket based broadcast

It is implemented in an asynchronous fashion

JSR-356 RemoteEndpoint.Async in action

Setup & deployment

You would need to configure Oracle Developer Cloud for the Continuous Build as well as Deployment process. You can refer to previous blogs for the same (some of the details specific to this example will be highlighted here)

References

Provide Oracle Application Container Cloud (configuration) descriptor

Deployment confirmation in Oracle Developer Cloud

Post-deployment status in Oracle Application Container Cloud

Test the application

You can either look up the price of a scrip (on-demand) using the REST endpoint or stream ORCL price by hooking on to the Websocket endpoint — both options have been summarized below

I would recommend using Simple WebSocket Client, which can be installed into Chrome browser as a plugin

Test the CI/CD flow

Make some code changes and push them to the Oracle Developer Cloud service Git repo. This should

  • Automatically trigger the build, which once successful will
  • initiate the deployment process, and
  • redeploy the new application version to Oracle Application Container Cloud

Don’t forget to…

The views expressed in this post are my own and do not necessarily reflect the views of Oracle.

--

--

Abhishek Gupta
Oracle Developers

Principal Developer Advocate at AWS | I ❤️ Databases, Go, Kubernetes