Skip to content

Java VS Code Case API Single Page Console Application

MsaasAPI edited this page Sep 24, 2018 · 31 revisions

CONTENTS

PREREQUISITE

INSTALL DEMO01

  1. There are multiple approaches to accomplish this:

  2. Unzip/Extract the folder.

  3. Open VS Code. Then open the project folder by either a. click Open Folder button, b. hotkey Ctrl K + Ctrl O, or c. File > Open Folder….

  4. Select target folder (extracted zip file folder) on File Explorer, and click Select Folder button.

  5. Build project - Open Command Palette by either a. hotkey F1, b. hotkey Ctrl + Shift P, or c. View > Command Palette….

  6. The following popup palette will appear at top center of VS Code window.

  7. Type the following command, and press Enter key.

    Tasks: Run Build Task
    

  8. Then type the following command, and press Enter key.

    Compile
    

  9. Then type the following command, and press Enter key.

    Continue without scanning the task output
    

  10. On the pop-up Integrated Terminal, verify the build is successful.

  11. Press F5 key to launch the debugger. During the first-time launch, select Java for the following pop-up query if prompted.

  12. If log4j verbose option is activated, hundreds of message lines may appear on console. Verify there is no error.

  13. Click Explorer icon on activity bar.

  14. Click Logs folder (This folder shall be automatically created during the project initial run).

  15. Click the first ever log file created under Logs folder, and log file will be opened on the right.

  16. The log generally contains at least one of the following:

    • Case number of a new case just created.
    • Case JSON of the case just created.
    • HTTP Status Code (200, 201, 204, etc).
  17. If no error is found in log file and on the console, we are ready to take deep look at the source code.

DEMO01 ANATOMY

  1. This project is architected in such a way that all Java codes are condensed in one single file Project.java, at the expense of poor object-oriented design. Only two files warrants our attention:

    • Program.java: Java codes.
    • pom.xml: dependencies.
  2. On Explorer, navigate to src > main > java > com > contoso > The Project Name > Program.java. Program.java will open on the right.

  3. In this application, the basic flow is:

    • Get access token (Bearer Token).
    GetRequestToken()
    
    • Compile header and payload (if any).
    SetPayloads()
    AddMetaDataToHttpRequest()
    
    • Make HTTP request (GET, POST, or PATCH).
    • Log returns.
  4. In Get access token stage, the ADAL for Java library is leveraged. The steps are as follow:

    • Retrieve SSL certificate from keystore configured in Set up SSL Keystore.
    • Extract private key and compile JWT to instantiate authContext.
    • Make POST request for token.
    • Receive and store access token.