Java developers are interested in connecting their Java applications to Oracle Autonomous Transaction Processing (ATP) and Oracle Autonomous Data Warehousing (ADW) and take full advantage of autonomous database capabilities (self-patching, self-tuning, fully managed etc., ). The Java applications can be deployed either on Oracle Cloud or on Microsoft Azure.This blog provides specific instructions to create, deploy, and run the Java applications connecting to ATP with Tomcat on Microsoft Azure using Eclipse as the IDE.
Let us get started with step by step instructions.
(1) Create ATP and Download client credentials:
(2) MS Azure Subscription: In order to deploy the Java web applications on Azure, you need to have signed up for MS Azure (https://azure.microsoft.com/). Note that this blog doesn't discuss or use Oracle's FastConnect.
(3) Eclipse IDE: Make sure you have a working Eclipse IDE with the workspace setup. We have used 'Eclipse Java EE IDE for Web Developers' in this blog.
(4) Install MS Azure toolkit: With Eclipse IDE, install MS Azure Toolkit that will make it easier to deploy the Java web app on Azure. Follow these steps to Install and sign-in to complete your MS Azure Toolkit setup.
First, create a Java web application using Eclipse that connects to ATP. Deploy the web app on Azure using the MS Azure Toolkit and invoke the servlet and make sure it is working. Follow these three simple steps to get your web application working on Azure.Create a Java webapp for ATP
Step 1: Create a webapp:
Click File --> New --> Dynamic Web Project. Choose the name of the webapp (e.g.,ATPWebApp) and click Finish.
Step 2: Download JDBC driver (ojdbc8.jar) and ucp.jar:
Download the latest 19.3 ojdbc8-full.tar.gz that includes JDBC driver (ojdbc8.jar) and ucp.jar and add it under <eclipse-workspace>/ATPWebApp/WebContent/WEB-INF/lib. Note to use ojdbc8.jar that is comptible with JDK8.
Note: When using JKS, remove oraclepki.jar, osdt_core.jar, and osdt_cert.jar from the classpath (lib folder). These additional jars are required only for Oracle Wallets.
Step 3: Unzip client credentials:
Unzip the client credentials (wallet_<dbname>.zip) file to <eclipse-workspace>/ATPWebApp/WebContent/WEB-INF/lib.
Java applications can use either JKS or Oracle Wallets to connect to the ATP database. The ojdbc.properties file is pre-configured for using Oracle Wallets.
When using JKS, add the below properties in ojdbc.properties. Note that the password used for these properties is the one used while downloading the client credentials zip file.
JKS related property in ojdbc.properties:
# Connection properties for using JKS.
# Keystore and trustStore passwords are the password used while
# downloading the client credentials zip file from console.
Step 4: Create a context.xml:
Follow these instructions for creating a context.xml with ATP database details. Refer to the sample below.
1. Place the context.xml under <eclipse-workspace>/ATPWebApp/WebContent/META-INF/context.xml
2. Update the database user and password to point to the ATP database that you have created.
3. Make sure the database URL has TNS alias. Check out tnsnames.ora or 'DB Connection' tab for the available services.
4. TNS_ADMIN should be pointed to /home/site/wwwroot/webapps/ROOT/WEB-INF/lib, when you deploy it on the ROOT. If you have chosen a different slot then change the path accordingly. Use KUDU to check the location of the web app after the deployment. (E.g., http://<webappname>.scm.azurewebsites.net)
Step 5: Create the Servlet:
By default, a index.jsp is created. We can use UCPServlet.java that has the code to connect to the database and perform some database operations. Copy the servlet and place it under <eclipse-workspace>/ATPWebApp/src. You must use the datasource name used in context.xml in the UCPServlet. Example., we are using 'UCP_atp' as the datasource.
Step 1: Build the Java project
Right click on the project and make sure you are using JDK8 as the compiler and 'Build Project'. Make sure there are no compilation errors.
Step 2: Deploy the Java webapp
Use Azure Tool Kit to deploy the web app on Azure as shown below. Make sure to login to your Azure account before the deployment.
Create an AppService on Azure as shown below. Choose the name of the app that you want to create. Example., ATPWebApp
After it is published on Azure, you can check the 'Azure Activity Log' that says "Published"
After the deployment, you can invoke the servlet at http://<webappname>.azurewebsites.net/<servletname>
Login to Azure website and under "AppServices" you can your web app. You can start/stop/restart your webapp.