Modernize WebLogic with Helidon

5
0
Send lab feedback

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.

  1. Open the Luna-Lab.html file located in the desktop. Here you will find the login tenant information required for this lab.

  2. Click on the OCI CONSOLE button to logon.

  3. Logon with the credentials provided.

  4. In the OCI Console select the Compute instances.

  5. Select your compartment in the compartment dropdown menu and click on your instance.

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

  7. Open a Terminal Emulator from the main desktop applications menu.

  8. 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.83
    https://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

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

  2. 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
  3. 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 &
  4. 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.

  5. Lets have a look at the WebLogic Admin Console and confirm it has started successfully.

    URL:

    http://EXTERNAL_IP:7101/console

    Example http://193.122.156.83:7101/console

    The WebLogic server started successfully.

  6. Logon using the following credentials.

    Username:

    weblogic

    Password:

    Oracle123!
  7. On the left window titled Domain Structure, click on Deployments. Notice the bestbank2020 application has been deployed and health OK.

  8. Open a new browser tab and open the bestbank application to confirm it is working.

     http://EXTERNAL_IP:7101/bestbank2020

    Example: http://193.122.156.83:7101/bestbank2020

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

  1. Create a directory called microservice and navigate to it.

    cd /u01/middleware_demo/wls-helidon
    mkdir microservice
    cd microservice
  2. 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

  3. 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
  4. Copy the following line of code.

    .register("/creditscore", new CreditscoreService())
  5. Using the down arrow key, goto line 86, press i for insert mode. The edit mode -- INSERT -- status will appear, like here.

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

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

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

  9. 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).

  10. Save your changes by, going in to command mode to write and quit vi.

    1. Press [ESC]
    2. Press [SHIFT] + : (change to command mode)
    3. Enter wq (the command for write and quit)
    4. Press [ENTER]

    The file should look like this.

  11. Now build the project by running the Helidon SE Maven command mvn.

    cd /u01/middleware_demo/wls-helidon/microservice/helidon-creditscore-se
    mvn package

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

  1. Open BestBank Web application index.xhtml HTML file in vi.

    vi /u01/middleware_demo/wls-helidon/src/main/webapp/index.xhtml
  2. 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.

  3. Save your changes by going in to command mode to write and quit vi.

    1. Press [ESC]
    2. Press [SHIFT] + : (change to command mode)
    3. Enter wq (the command for write and quit)
    4. Press [ENTER]

Modify BestBank Server Side

Modify the server side bean (Java program file) to invoke Credit Score Microservices Application.

  1. 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
  2. Find and delete all the lines which contain REMOVE THIS LINE comment (6 lines to be removed).

  3. Save your changes by going in to command mode to write and quit vi.

    1. Press [ESC]
    2. Press [SHIFT] + : (change to command mode)
    3. Enter wq (the command for write and quit)
    4. 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.

  1. Using the vi tool, open the java bean file.

    vi /u01/middleware_demo/wls-helidon/src/main/resources/app.properties
  2. 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.

  3. Save your changes by going in to command mode to write and quit vi.

    1. Press [ESC]
    2. Press [SHIFT] + : (change to command mode)
    3. Enter wq (the command for write and quit)
    4. Press [ENTER]

Deploy BestBank Application

In this step, you will deploy the new feature.

  1. Change to the directory wls-helidon where the Bank Application code reside.

    cd /u01/middleware_demo/wls-helidon
  2. Run the following Maven command to deploy the package.

    mvn clean package

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

    Example http://193.122.156.83:7101/bestbank2020_01

  4. Select a line and click view. You should notice the service is not running yet.

  5. 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
  6. Start the microservice application as a standalone Java program.

    java -jar helidon-creditscore-se.jar &

    Notice the port number which the service is using.

  7. Finally, test again. Refresh the existing browser tab to test the changes.

     http://EXTERNAL_IP:7101/bestbank2020_01

    Example http://193.122.156.83:7101/bestbank2020_01

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

SSR