Before You Begin
This 15-minute tutorial shows you how to connect a Java application to Oracle Data Hub Cloud Service and how to deploy your application to Oracle Application Container Cloud Service.
Background
Oracle Application Container Cloud Service lets you deploy Go, Java Platform, Standard Edition (Java SE), Node.js, PHP, Python, Ruby, and Enterprise Edition (Java EE) applications to the Oracle Cloud.
This tutorial provides you a sample application that creates a connection to Oracle Data Hub Cloud Service. To create the connection it uses the environment variables DHCS_CLIENT_PORT, DHCS_USER_NAME, DHCS_USER_PASSWORD, and DHCS_NODE_LIST that are provided by Oracle Application Container Cloud Service. The environment variables are created when you create the service binding. In this tutorial, you create the service binding to Oracle Data Hub Cloud Service by using a deployment.json file.
What Do You Need?
- Access to an instance of Oracle Application Container Cloud Service
- An Oracle Data Hub Cloud Service instance. See Creating an Apache Cassandra Cluster in Oracle Data Hub Cloud Service
- Downloaded employees-app-dhcs.zip
- Maven 3.0+
- cURL 7.0+ with Secure Sockets Layer (SSL) support
Prepare the Application for Cloud Deployment
- Extract the contents of the
employees-app-dhcs.zipfile in your local system. - In the
employees-app-dhcsdirectory, create themanifest.jsonfile and add the following content.{ "runtime":{ "majorVersion": "8" }, "command": "java -jar simple-service-1.0-SNAPSHOT.jar", "notes": "Sample app to create an Oracle Data Hub Cloud Service connection." } - In the same directory, create the
deployment.jsonfile and add the following content:{ "services": [{ "name": "Name of your Oracle Data Hub Cloud Service instance", "type": "DHCS", "username": "Your database user name", "password": "Your database password" }] } - Open a command-line window (or terminal in Linux), go to the
employees-app-dhcsdirectory and compile and package the application.mvn compile package
Deploy the Application to Oracle Application Container Cloud Service
- Open the Oracle Application Container Cloud Service console.
- In the Applications list view, click Create Application and select Java SE.
- In the Application section, enter a name for your application and click Browse.
- On the File Upload dialog box, select
simple-service-1.0-SNAPSHOT-dist.ziplocated in thetargetdirectory and click Open. - Keep the default values in the Instances and Memory fields. Click More options, and then click Browse next to Deployment Configuration.
- On the File Upload dialog box, select the
deployment.jsonfile that you created in the previous section and click Open. - Click Create.
- Wait until the application is created. The URL is enabled when the creation is completed. Copy the URL you'll use it in the next section.
Test the Application
In this section, you test your application by using cURL commands. In all the cURL commands, replace the app_endpoint placeholder with the
URL of your application.
- Open a command-line window (or terminal in Linux).
-
Setup the database.
curl app_endpoint/myapp/employees/setup - Create an employee record.
curl -i -X POST -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\", \"lastName\" : \"Smith\",\"birthDate\":\"1957-10-14\", \"phone\":\"193-754-4112\",\"email\":\"john.smith@example.com\",\"role\" : \"Manager\",\"department\" : \"Sales\" }" app_endpoint/myapp/employees - Query all employee entities. From the results, write down the ID of the employee, you'll use it in the next step.
curl app_endpoint/myapp/employees - Update the employee. Replace the
id-employeeplaceholder with the ID of the previous step.curl -i -X PUT -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\", \"lastName\" : \"Smith\",\"birthDate\":\"1957-12-08\",\"email\":\"john.smith@example.com\",\"role\" : \"Manager\",\"department\" : \"IT\" }" app_endpoint/myapp/employees/id-employee - Delete the employee.
curl -i -X DELETE app_endpoint/myapp/employees/id-employee
Want to Learn More?
- Oracle Application Container Cloud Service: Get Started in the Oracle Help Center
- Oracle Data Hub Cloud Service: Tasks in the Oracle Help Center
Connect a Java Application to Oracle Data Hub Cloud Service