-
Notifications
You must be signed in to change notification settings - Fork 1
Java VS Code Case API Single Page Console Application
- Complete Get Started with VS Code for Java.
- Complete Set up SSL Keystore for Java Case API Application.
-
There are multiple approaches to accomplish this:
- Download entire repository: Navigate to repository home page, and then click Clone or download button to download entire folder. This is NOT advisable due to its huge size (containing many images for wiki pages and projects in multiple programming languages).
- Download specific folder (Demo01) via SVN.
- Download specific folder (Demo01) via browser extension/addon. The demo may be found in Download Certain Project from Git Repository wiki page.
- Download entire repository: Navigate to repository home page, and then click Clone or download button to download entire folder. This is NOT advisable due to its huge size (containing many images for wiki pages and projects in multiple programming languages).
-
Unzip/Extract the folder.
-
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….
-
Select target folder (extracted zip file folder) on File Explorer, and click Select Folder button.
-
Build project - Open Command Palette by either a. hotkey F1, b. hotkey Ctrl + Shift P, or c. View > Command Palette….
-
The following popup palette will appear at top center of VS Code window.
-
Type the following command, and press Enter key.
Tasks: Run Build Task
-
Then type the following command, and press Enter key.
Compile
-
Then type the following command, and press Enter key.
Continue without scanning the task output
-
On the pop-up Integrated Terminal, verify the build is successful.
-
Press F5 key to launch the debugger. During the first-time launch, select Java for the following pop-up query if prompted.
-
If log4j verbose option is activated, hundreds of message lines may appear on console. Verify there is no error.
-
Click Explorer icon on activity bar.
-
Click Logs folder (This folder shall be automatically created during the project initial run).
-
Click the first ever log file created under Logs folder, and log file will be opened on the right.
-
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).
-
If no error is found in log file and on the console, we are ready to take deep look at the source code.
-
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.
-
On Explorer, navigate to src > main > java > com > contoso > The Project Name > Program.java. Program.java will open on the right.
-
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.
-
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.