Modernize Enterprise Java Apps using WebLogic and Helidon Microservices Workshop
Introduction
Description
Learn how to setup integrate Oracle WebLogic with Helidon. Running you microservices alongside WebLogic Server.
Estimated Lab Time: 90 minutes
About Oracle WebLogic
Oracle WebLogic Server provides a modern development platform for building applications, a runtime platform for high performance and availability, and rich management tooling for efficient and low cost operations.
About Oracle Helidon
Helidon is a open-source framework, a collection of Java libraries designed for creating microservices-based applications.
Lab Objectives
- To seamlessly integrate an application running on WebLogic with a Helidon microservice
- Build and deploy a Helidon microservice using Maven
- Run a Helidon microservice
STEP 1: Initialize environment
In this lab we will logon and start all components required to complete this workshop successfully.
Open the Luna-Lab.html file located in the desktop. Here you will find the login tenant information required for this lab.
Click on the OCI CONSOLE button to logon.
Logon with the credentials provided.
In the OCI Console select the Compute instances.
Select your compartment in the compartment dropdown menu and click on your instance.
Find the Public IP address of your instance and copy it. The next step will require the IP address as we will connect to the instance via the terminal.
Open a Terminal Emulator from the main desktop applications menu.
From the terminal window enter the following SSH command. (Replace EXTERNAL_IP with the IP information from the instance.)
The -i switch is where you designate the name of the public key (.pub) and following that is the IP address of your compute instance prefaced by the default admin user name, opc and the @ sign. Answer yes to the prompt about accepting the identity and adding to the list of known hosts.
ssh -i ~/.ssh/id_rsa opc@EXTERNAL_IP
Example ssh -i ~/.ssh/id_rsa
opc@193.122.156.83https://luna.oracle.com/api/v1/labs/9395d6ce-5bf0-4c4f-9269-6bd1387a2ed0/gitlab/javascript:void(0)
if you are not successful try without the public key.
ssh opc@EXTERNAL_IP
You have successfully logon to your server instance as user opc.
Start the WebLogic server
To start the WebLogic server (WLS), you must logon as the oracle user. Return to the terminal window enter the following command to logon as oracle user.
sudo su - oracle
Run these scripts to set the environment variables required to start the webLogic 14c Admin server and for Helidon.
cd /u01/middleware_demo/scripts . ./setWLS14Profile.sh . ./setBankAppEnv.sh
To start the WLS, change the working directory to WebLogic 14c domain bin and start AdminServer in the wls domain.
cd $DOMAIN_HOME/bin nohup sh startWebLogic.sh &
Monitor the output until the log shows the server is running. You might have to press [ENTER] again to get a command prompt.
tail -f nohup.out
When you see the log output as running, press [CTRL] + C to exit the tail command.
Lets have a look at the WebLogic Admin Console and confirm it has started successfully.
URL:
http://EXTERNAL_IP:7101/console
The WebLogic server started successfully.
Logon using the following credentials.
Username:
weblogic
Password:
Oracle123!
On the left window titled Domain Structure, click on Deployments. Notice the bestbank2020 application has been deployed and health OK.
Open a new browser tab and open the bestbank application to confirm it is working.
http://EXTERNAL_IP:7101/bestbank2020
Check the Helidon artifacts are there.
On the Cloud Shell console, goto the application folder.
cd /u01/middleware_demo/wls-helidon
Display the folder content. Verify the file pom.xml and src folder is there.
ls -l
STEP 2: Modernize with WebLogic and Helidon
In this lab we will walk you through the steps for deploying and testing of the newly deployed credit verification feature.
Develop new Credit Score Function
In this step, you will develop the new Credit Score Function as a microservice using Helidon.
Create a directory called microservice and navigate to it.
cd /u01/middleware_demo/wls-helidon
mkdir microservice
cd microservice
Deploy a project using the Helidon SE Maven command mvn.
mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=io.helidon.archetypes -DarchetypeArtifactId=helidon-quickstart-se -DarchetypeVersion=2.2.0 -DgroupId=io.helidon.bestbank -DartifactId=helidon-creditscore-se -Dpackage=io.helidon.bestbank.creditscore
When the project generation is ready, add the route to the program. Open the file Main.java using the edit tool vi.
vi helidon-creditscore-se/src/main/java/io/helidon/bestbank/creditscore/Main.java
Copy the following line of code.
.register("/creditscore", new CreditscoreService())
Using the down arrow key, goto line 86, press i for insert mode. The edit mode -- INSERT -- status will appear, like here.
Paste the code you copied in the previous step. Press [CTRL] + V (if using windows OS or right click mouse if using terminal) to insert the code and press [ENTER]. You may want to insert spaces to align the next line. Your changes should look like this here.
Save your changes by, going in to command mode to write and quit vi.
Press the [ESC] key, then press [SHIFT] + : (Shift and colon) to enter the command mode.
When you see the colon appear at the bottom left corner, enter wq (write and quit) and press [ENTER].
Here is the final result of the change.
Now create a new class called CreditscoreService in the same package where the Main.java is located.
For ease of execution the class file has already been created. Simply run the following command to copy it to the correct location.
cp /u01/middleware_demo/scripts/CreditscoreService.java helidon-creditscore-se/src/main/java/io/helidon/bestbank/creditscore
Note The code accepts a GET for healthcheck and POST method to calculate the credit score value based on the account owner's details which passed using JSON.
Change the port number of the microservice by changing from 8080 to 8081.
vi /u01/middleware_demo/wls-helidon/microservice/helidon-creditscore-se/src/main/resources/application.yaml
Go to line 6. Move cursor to the number 0. Press the key r (for replace) and then the key 1 (replace the 0 with 1).
Save your changes by, going in to command mode to write and quit vi.
- Press [ESC]
- Press [SHIFT] + : (change to command mode)
- Enter wq (the command for write and quit)
- Press [ENTER]
The file should look like this.
Now build the project by running the Helidon SE Maven command mvn.
cd /u01/middleware_demo/wls-helidon/microservice/helidon-creditscore-se mvn package
Check the executable jar file of the Helidon microservice.
cd target ls helidon-creditscore-se.jar
Modify BestBank Web user interface
In this step, you will modify the BestBank user interface by creating a view button which opens the account owner details window. This detail window will show the credit score value of the account owner.
Open BestBank Web application index.xhtml HTML file in vi.
vi /u01/middleware_demo/wls-helidon/src/main/webapp/index.xhtml
Find and delete all the lines which contain REMOVE THIS LINE comment (4 lines to be removed).
Starting from the top of the file, using the down arrow key, go to the line you want to delete and press dd (Press the key d twice).
Using the down arrow key, go to the next REMOVE THIS LINE comment line and press dd. Repeat until all the lines have been removed.
Shown here is the last line to remove.
If you are familiar with JSF, check what has changed in the code.
Save your changes by going in to command mode to write and quit vi.
- Press [ESC]
- Press [SHIFT] + : (change to command mode)
- Enter wq (the command for write and quit)
- Press [ENTER]
Modify BestBank Server Side
Modify the server side bean (Java program file) to invoke Credit Score Microservices Application.
Using the vi tool, open the java bean file.
vi /u01/middleware_demo/wls-helidon/src/main/java/com/oracle/oow19/wls/bestbank/AccountOwnerBean.java
Find and delete all the lines which contain REMOVE THIS LINE comment (6 lines to be removed).
Save your changes by going in to command mode to write and quit vi.
- Press [ESC]
- Press [SHIFT] + : (change to command mode)
- Enter wq (the command for write and quit)
- Press [ENTER]
Configure the End-Point
The Bank Web Application reads this properties file to obtain the endpoint URL. However, the best practice is to use a API tool for better security and managment of the endpoints, such as Oracle API Manager Cloud.
Using the vi tool, open the java bean file.
vi /u01/middleware_demo/wls-helidon/src/main/resources/app.properties
Replace the first line with the following. Press the key d twice to delete the line, press i and then paste the following line.
creditscore.url=http://localhost:8081/creditscore
Your changes should look like this.
Save your changes by going in to command mode to write and quit vi.
- Press [ESC]
- Press [SHIFT] + : (change to command mode)
- Enter wq (the command for write and quit)
- Press [ENTER]
Deploy BestBank Application
In this step, you will deploy the new feature.
Change to the directory wls-helidon where the Bank Application code reside.
cd /u01/middleware_demo/wls-helidon
Run the following Maven command to deploy the package.
mvn clean package
When the build is successful, open the browser and access the new bank application. You can just add _01 to the tab you opened earlier.
http://EXTERNAL_IP:7101/bestbank2020_01
Select a line and click view. You should notice the service is not running yet.
Start the service. Change to the folder with the jar file you compiled earlier.
cd /u01/middleware_demo/wls-helidon/microservice/helidon-creditscore-se/target
Start the microservice application as a standalone Java program.
java -jar helidon-creditscore-se.jar &
Notice the port number which the service is using.
Finally, test again. Refresh the existing browser tab to test the changes.
http://EXTERNAL_IP:7101/bestbank2020_01
Select an account owner and click the view button. A pop-up window with CreditScore information will be displayed like here.
Congratulations!
You have successfully completed the labs.
To end this session click End Session button in the toolbar.