X

Learn Tips and Best Practices from the Oracle JDBC Development

  • August 26, 2019

Create, Deploy, and Run Java apps connecting to ATP on Azure (Eclipse)

Nirmala Sundarappa
Principal Product Manager

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.

Pre-requisites

(1) Create ATP and Download client credentials:

  • Login to your oracle cloud at cloud.oracle.com and create ATP in a few simple steps.
  • Download the client credentials file (wallet_dbname.zip) from "DB Connection" tab of ATP database that you created. Contents of the zip file are: tnsnames.ora, ojdbc.properties, sqlnet.ora, cwallet.ora, ewallet.p12, truststore.jks, keystore.jks
  • Make sure to check the version of the JDBC driver and JDK and other necessary steps by going through this section

(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. 

Java webapp 

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
Deploy a Java webapp on Azure
Run a Java webapp 


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. 
oracle.net.ssl_server_dn_match=true
javax.net.ssl.trustStore=${TNS_ADMIN}/truststore.jks
javax.net.ssl.trustStorePassword=<password_from_console>
javax.net.ssl.keyStore=${TNS_ADMIN}/keystore.jks
javax.net.ssl.keyStorePassword=<password_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) 
 <Context>

<Resource name="tomcat/UCP_atp" auth="Container"
   factory="oracle.ucp.jdbc.PoolDataSourceImpl"
   type="oracle.ucp.jdbc.PoolDataSource"
   description="UCP Pool in Tomcat"
   connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource"
   minPoolSize="5"
   maxPoolSize="50"
   initialPoolSize="15"
   user="jdbcuser"
   password="XXXXXXX"
   url="jdbc:oracle:thin:@dbtest_medium?TNS_ADMIN=/home/site/wwwroot/webapps/ROOT/WEB-INF/lib"
 />
</Context>

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. 

Deploy a Java web app on Azure

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" 

Run the web app

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. 

Example., http://atpwebapp.azurewebsites.net/UCPServlet 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.