Oracle by Example brandingConnect a Java Application to Oracle Data Hub Cloud Service

section 0Before 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?


section 1Prepare the Application for Cloud Deployment

  1. Extract the contents of the employees-app-dhcs.zip file in your local system.
  2. In the employees-app-dhcs directory, create the manifest.json file 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."
    } 
  3. In the same directory, create the deployment.json file 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" 
      }]
    } 
  4. Open a command-line window (or terminal in Linux), go to the employees-app-dhcs directory and compile and package the application.
    mvn compile package 

section 2Deploy the Application to Oracle Application Container Cloud Service

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application and select Java SE.
  3. In the Application section, enter a name for your application and click Browse.
  4. On the File Upload dialog box, select simple-service-1.0-SNAPSHOT-dist.zip located in the target directory and click Open.
  5. Keep the default values in the Instances and Memory fields. Click More options, and then click Browse next to Deployment Configuration.
  6. On the File Upload dialog box, select the deployment.json file that you created in the previous section and click Open.
  7. Click Create.
  8. 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.

section 3Test 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.

  1. Open a command-line window (or terminal in Linux).
  2. Setup the database.
    curl app_endpoint/myapp/employees/setup
  3. 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
  4. 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
  5. Update the employee. Replace the id-employee placeholder 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
  6. Delete the employee.
    curl -i -X DELETE app_endpoint/myapp/employees/id-employee

more informationWant to Learn More?