Inside a Java Mobile Application, Part 3
Using Java and JavaFX to create Java client applications that work on mobile devices.
by Johan Vos

This article is Part 3 of a series. In Part 2, we explored how to run Gluon CloudLink in Oracle Cloud. That allowed us to connect a mobile app (written with Gluon Mobile) to a back-end system in a mobile- and cloud-friendly way. In Part 2, we also auto-provisioned Gluon CloudLink onto the Oracle Cloud infrastructure. The details of deploying applications on Oracle Cloud were hidden for the developer.

In this article, we will explore the details on how to install a project consisting of a number of microservices onto Oracle Cloud.

Gluon CloudLink is a mobile back-end as a service (MBaaS). It is deployed at but it can also be deployed inside VPNs or on third-party cloud systems, for example, Oracle Cloud. In that case, customers provisions their private copies of Gluon CloudLink, and they benefit from the same functionality as the public cloud version.

This article simplifies some of the concepts of the Gluon CloudLink architecture to make it easier to understand. For example, Gluon CloudLink has an API gateway that makes sure that requests that are made to a particular microservice are signed with the proper credentials.

An MBaaS contains a number of functions, and Gluon CloudLink implements these functions as a set of microservices. Each microservice is a stateless Java EE 7 application that is executed inside a Payara Micro server. Each microservice exposes its functionality via a set of REST endpoints that other microservices in the same network can connect to.

When Gluon CloudLink is deployed to Oracle Cloud, the microservices are deployed inside Oracle Application Container Cloud, which has built-in functionality that addresses some of the issues typically encountered when deploying microservices in a clustered, scalable environment.


In order to follow the steps in this article, you should have an Oracle Cloud account. If you don't have one, you can apply for a free 30-day trial at

After completing the sign-up process, there are four important keys you need to remember:

  • User Name, which we'll later expect to be in the ${USER_ID} parameter.
  • Password, which we'll later expect to be in the ${USER_PASSWORD} parameter.
  • Identity Domain, which we'll later expect to be in the ${ID_DOMAIN} parameter. Note that a domain has a name and an ID, and that you need the ID here.
  • Region. If you are accessing a US data center, the parameter ${APAAS_HOST} that is used later will be If you access a Europe-based data center, the ${APAAS_HOST} parameter should be

You will need those when logging in via the web-based service console, or you will need to provide them if you use the REST-based approach.

Deploying a Single Application

In Oracle Application Container Cloud terminology, each microservice is an application. A number of applications can be installed into the Oracle Application Container Cloud environment. The Gluon CloudLink provisioning tool installs nine microservices (hence, nine applications) into the Oracle Application Container Cloud environment of the Oracle Cloud subscriber.

An Oracle Application Container Cloud application is a zip file that contains the required code and resources to run the application, along with a manifest.json file that will be parsed by Oracle Application Container Cloud.

A basic manifest.json file looks like this:

    "runtime": {
        "majorVersion": "8"
    "command": "java -jar payara-micro- --deploy helloworld.war",

The runtime block states that we want to run with a Java 8 virtual machine (VM).

The command block describes the command that will be executed. In this first example, we have a very simple application that just requires a WAR file to be deployed inside the Payara Micro container. Both the payara-micro- file and the helloworld.war file should be included in the zip file, for example:

  • manifest.json
  • payara-micro-
  • helloworld.war

This zip file can now be uploaded to the Oracle Application Container Cloud. There are two ways of doing this: either via the Oracle Application Container Cloud service console or via a REST call. The Gluon Dashboard that provisions Gluon CloudLink to Oracle Cloud creates a number of REST calls using Java code. In this article, we'll see some REST calls that can be executed using the curl command. Keep in mind that those calls can be done using Java as well; hence, the whole flow can be automated in a Java application, as done by Gluon Dashboard today, when you choose to use Gluon CloudLink on Oracle Cloud.

Uploading via the Oracle Application Container Cloud service console requires you to log in to Oracle Cloud, select Oracle Application Container Cloud, and click Service Console. You can then create new applications, as shown in the screenshot below:

Figure 1. Screen where you can create new applications

You first have to choose what kind of a service you want to deploy: Java, PHP, or JavaScript.

Figure 2. Screen where you choose the type of service

The microservices we are creating are all Java based; hence, you should select that.

The next screen allows you to give the application a name and upload it.

Figure 3. Screen where you name the application

Note that at this stage, you can already decide about scalability. You can have multiple instances for the service, you can scale up by adding more memory to a single instance, or both.

Uploading an application via the REST interface requires a few extra steps. The application first needs to be uploaded to a container in Oracle Cloud Infrastructure Storage, which is OpenStack Swift–compliant and uses the Swift model of containers and container items.

Before an application can be uploaded to the container, we need to make sure we have one. This is achieved with the following curl command:

curl -i -X PUT \
	    -u ${USER_ID}:${USER_PASSWORD} \

The parameters used here are described in the Prerequisites section. The result of this call is the creation of a storage container named hello.

Now we can upload the application to the container, using the following curl command:

curl -i -X PUT \
	   -u ${USER_ID}:${USER_PASSWORD} \
	    https://${ID_DOMAIN}$ID_DOMAIN/hello/ \

Finally, we can create the application on Oracle Application Container Cloud:

curl -i -# -X POST \
  -H "Content-Type: multipart/form-data" \
  -F "name=${APP_NAME}" \
  -F "runtime=${RUNTIME}" \
  -F "subscription=Hourly" \
  -F archiveURL=hello/ \

Now that your application is uploaded to Oracle Cloud, you can use it. The service console provides the URL that is now hosting your application. Figure 4 shows the Gluon CloudLink "data" microservice that is uploaded in an Oracle Application Container Cloud container, and it is accessible via the URL that is shown at the bottom of the console:

Figure 4. Service console showing the URL for the uploaded microservice

The application should be accessed using HTTPS (using the default port 443). Oracle Application Container Cloud will forward traffic it receives at port 443 to port 8080 of the deployed application, which is also the default HTTP port for Payara Micro.

Interapplication Communication

So far, we deployed only a single application on Oracle Application Container Cloud. As stated before, Gluon CloudLink contains a number of microservices that communicate with each other. Oracle Application Container Cloud provides support for this configuration. Each microservice can be deployed as a separate application on Oracle Application Container Cloud, and each is accessible to other microservices deployed in the same container by using a simple HTTP request, where the host name is the name of the application.

Internally, each Oracle Application Container Cloud application is running inside a Docker container, and the communication between the applications is achieved using the internal Docker overlay network.

The only required change is adding the isClustered property in the manifest.json file that is part of the application zip file, which now becomes this:

        "runtime": {
            "majorVersion": "8"
        "command": "java -jar payara-micro- --deploy helloworld.war",
        "isClustered" : true

If the application is named hello, other applications in the same host will be able to access this application using http://hello:8080/path/to/restendpoint.

For example, if the helloworld.war file is deployed at the "helloworld" URL, and it exposes a REST endpoint at "say/hi," that endpoint can be accessed by another application in the same Oracle Application Container Cloud environment by calling http://hello:8080/helloworld/say/hi.

Note that both the application exposing its endpoints and the one calling the application need to have the isClustered property set to true in their manifest.json files.

The Oracle Cloud infrastructure will route the requests towards the required application instance.

Using Services

Most enterprise applications need data persistency. Oracle Cloud provides the option to create an Oracle Database service or a MySQL Database service.

In Oracle Application Container Cloud, you can bind an application to a database service that is running in the same domain by adding a service binding. This way, you can bind the Gluon CloudLink microservices with a database in Oracle Cloud. When an application is bound, the configuration details for connecting to the database will be added as environment variables.

In our sample, we leverage Oracle MySQL Cloud Service. Clicking Create Service renders a simple wizard that will create the MySQL service.

Gluon CloudLink uses Java Persistence API (JPA) for storing relational data. Inside the microservice itself, a persistence.xml configuration file defines the name of the datasource:


The link between the datasource and the physical database is made in the gcl-domain.xml file, where a jdbc-resource named jdbc/datasource is defined:

<jdbc-resource pool-name="gluoncloudlink_mysql_jdbc_pool" jndi-name="jdbc/datasource"></jdbc-resource>

This resource now points to a pool named gluoncloudlink_mysql_jdbc_pool, which is defined as follows in the same gcl-domain.xml file:

	<jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 
    		                name="gluoncloudlink_mysql_jdbc_pool" res-type="javax.sql.DataSource">
	<property name="useUnicode" value="true"></property>
	<property name="driverClass" value="com.mysql.jdbc.Driver"></property>      
	<property name="user" value="MYSQL_USER"></property>
	<property name="password" value="MYSQL_PASSWORD"></property>
	<property name="characterEncoding" value="utf8"></property>
	<property name="portNumber" value="MYSQL_PORT"></property>
	<property name="databaseName" value="MYSQL_DATABASE"></property>
	<property name="serverName" value="MYSQL_HOST"></property>

The values for the uppercase names should come from the created MySQL Database service.

Before the microservice can access the MySQL Database service, a binding needs to be created. This can be done manually from the service console by selecting the application and clicking Service Bindings - add. The type and the name of the service need to be entered, and then the service binding is active.

Cloud Stack

Gluon CloudLink is a complex application containing a number of microservices that need to be deployed in Oracle Application Container Cloud together with one or more data storage services. Rather than creating and configuring the microservices and the other services one by one, microservices can be created in a single step using the Oracle Cloud Stack. Via a web console or a REST interface, Oracle Cloud Stack allows you to define a template and create a whole stack that is defined by the template.

A template describes a number of services and allows for parameters being shared across services.

Using a template makes it easier and more convenient to perform all steps in a single command, but it adds a bit of complexity because some of the properties that are created by services should be leveraged by other services already.

This is, for example, the case with Oracle MySQL Cloud Service. Fortunately, the properties from this service are exposed as environment variables.

In the startup script for the microservices that use Oracle MySQL Cloud Service, we replace the placeholders for the database properties with the generated environment variables.

Oracle MySQL Cloud Service adds the following environment variables:


The custom gcldomain.xml configuration is updated before Payara Micro is launched by using the environment variables that are provided by the service binding.

This implies that the launch command for the application needs to be changed. Rather than immediately executing the Payara Micro server, we need to start a shell script that first replaces the MYSQL properties in gcldomain.xml with the properties provided by Oracle MySQL Cloud Service.

That shell script looks as follows:

sed -i "s/MYSQL_HOST/${MYSQLCS_CONNECT_STRING%%:*}/g" gcldomain.xml
sed -i "s/MYSQL_PORT/${MYSQLCS_MYSQL_PORT}/g" gcldomainl.xml
sed -i "s/MYSQL_DATABASE/${MYSQLCS_CONNECT_STRING##*/}/g" gcldomain.xml
sed -i "s/MYSQL_USER/${MYSQLCS_USER_NAME}/g" gcldomain.xml
sed -i "s/MYSQL_PASSWORD/${MYSQLCS_USER_PASSWORD}/g" gcldomain.xml
java -classpath mysql-connector-java-5.1.40.jar:payara-micro- fish.payara.micro.PayaraMicro --deploy 3.war --domainConfig gcldomain.xml

Note that we added the MySQL driver to the classpath and that we have to provide the gcldomain.xml file, which is the modified version of the built-in domain.xml file.


In this article, we extended the OTN demo app from the previous article. Rather than showing a hardcoded list of coffee types, we retrieved the list from a back-end service. However, we didn't access that back-end service directly; we used middleware called Gluon CloudLink that bridges the gap between the mobile devices and the enterprise infrastructure.

We explored how you can provision Gluon CloudLink on your Oracle Cloud infrastructure, and how you can easily configure Gluon CloudLink using its dashboard to map client requests onto external requests by defining functions that can be called on the mobile client.

About the Authors
Johan Vos started working with Java in 1995. He was part of the Blackdown team, porting Java to Linux. His main focus is on end-to-end Java, combining back-end systems and mobile/embedded devices. He received a Duke's Choice Award in 2014 for his work on JavaFX on mobile devices.
In 2015, he cofounded Gluon, which allows enterprises to create mobile Java client applications leveraging their existing back-end infrastructure. Gluon received a Duke's Choice Award in 2015. Vos is a Java Champion, a member of the BeJUG steering group and the Devoxx steering group. and he is a JCP member. He is the lead author of Pro JavaFX 8 (Apress, 2014), and he has been a speaker at numerous conferences on Java.
Join the Java Community Conversation
Experience Oracle Cloud—Get US$300 in free cloud credits.