Develop and deploy a Microprofile application on Oracle Cloud
This blog demonstrates how to get started with a simple application based on the Microprofile specification
- Leverage Wildfly Swarm as the Microprofile implementation
- Run it on Oracle Application Container Cloud
- CI/CD using Oracle Developer Cloud
About the sample application
The application is dead simple — available here. Before diving into its details, let’s look at Microprofile and Wildfly Swarm
Eclipse Microprofile … ?
Microprofile is an open source initiative whose goal is to provide an optimized runtime & platform for running Java based microservices. Here is an overview
- It’ currently in the Incubation phase as a project under the Eclipse Foundation
- There are multiple implementations of the specification — Wildfly Swarm, Payara, TomEE, WebSphere Liberty
- Leverages existing and widely used Java EE specifications along with other technologies
- As of now, the Microprofile supports JAX-RS, CDI and JSON-P specifications from the Java EE umbrella
Please check the following links for details — Microprofile on Eclipse, microprofile.io
Wildfly Swarm
This example uses Wildfly Swarm as an implementation of the Microprofile specification. You can read more about Wildfly Swarm here
Implementation details
In this section, we will explore how the application uses the supported specifications i.e. CDI, JAX-RS and JSON-P
- JAX-RS: The JAX-RS resource exposes a REST endpoint to fetch stock prices — it’s actual implementation is realized by internal helper classes
- JSON-P: Stock data (semi JSON payload) returned by the source (in this case, the Google Finance endpoint) is a cleaned up and then parsed by
StockDataParserwhich uses the JSON-P API
CDI: It serves as the glue and helps in multiple ways
- Exposes application classes as CDI beans —
StockDataParser(@ApplicationScoped) andStockPriceRetriever(@Dependent) - Leverages JAX-RS & CDI integration point — designates a JAX-RS
@Provider(theExceptionMapperimplementations) as@ApplicationScopedCDI beans — for more details please check section 10.2.3 of the JAX-RS specification - beans.xml enables all the CDI magic in the background
JAX-RS resource
@Path("stocks")
public class StockPriceResource {
@Inject
private StockPriceRetriever stock;
@GET
public Response getQuote(@QueryParam("ticker") final String ticker) {
return Response.ok(stock.getPrice(ticker)).build();
}
}Application logic (CDI bean)
@Dependent
public class StockPriceRetriever {
@Inject
private StockDataParser parser;
public String getPrice(String ticker) {
String tick = null;
if (ticker == null) {
throw new InvalidTickerException();
}
Future<Response> promise = ClientBuilder.newClient().
target("https://www.google.com/finance/info?q=NASDAQ:" + ticker).
request().async().get();Exception Mapper — yet another CDI bean
@Provider
@ApplicationScoped
public class InvalidTickerExceptionMapper implements ExceptionMapper<InvalidTickerException>{
public InvalidTickerExceptionMapper() {
}
@Override
public Response toResponse(InvalidTickerException e) {
return Response.status(400).entity(e.getMessage()).build(); //Bad Request
}
}Dynamic port binding
When deployed to Oracle Application Container Cloud, the application dynamically binds to port exposed by the PORT environment variable
- Wildfly Swarm exposes this as a system property — swarm.https.port
- This in turn is used in the startup command within the manifest.json (which is a deployment descriptor)
{
"runtime":{"majorVersion":"8"},
"command":"java -jar -Dswarm.https.port=$PORT -Dswarm.context.path=/ accs-microprofile-swarm.jar",
"notes":"Sample Microprofile app on ACCS"
}Setup
Oracle Developer Cloud
Let’s 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
- Bootstrap the application in Oracle Developer Cloud — Project & code repository creation
- Continuous integration setup — Configure build job
- Deployment setup — Continuous Deployment (CD) to Application Container Cloud
Provide Oracle Application Container Cloud (configuration) descriptor

Deployment confirmation in Oracle Developer Cloud

Post-deployment status in Application Container Cloud

Test the application
Its super simple! Just pick a HTTP client — browser, Postman.. anything
- Access https://accs-microprofile-sample-<yourdomain>.apaas.<dc>.oraclecloud.com/stocks?ticker=ORCL — you should see a HTTP 200 with the price info e.g. https://accs-microprofile-sample-domain007.apaas.us.oraclecloud.com/stocks?ticker=ORCL
- Access https://accs-microprofile-sample-<yourdomain>.apaas.<dc>.oraclecloud.com/stocks — the JAX-RS exception mapper will kick in and you should see a HTTP 400 with the error message
- Access https://accs-microprofile-sample-<yourdomain>.apaas.<dc>.oraclecloud.com/stocks?ticker=invalid_val - the JAX-RS exception mapper will kick in and you should see a HTTP 500
Test the CI/CD flow
Make some code changes and push them to the Developer Cloud service Git repo. This should
- Automatically trigger the build, which once successful will
- Automatically trigger the deployment process, and
- Redeploy the new application version to Oracle Application Container Cloud
Don’t forget to…
- check out the tutorials for Oracle Application Container Cloud — there is something for every runtime !
- other blogs on Application Container Cloud
The views expressed in this post are my own and do not necessarily reflect the views of Oracle.

