AS/400 COBOL RPC SDK Exercise
Introduction
This exercise will develop your skills with OpenLegacy IDE by generating Java models from existing sources and creating unit tests to validate backend connectivity and data.
Pre-Requirements
OpenLegacy IDE version 4.5.5 (Full installation including JDK and all Maven dependencies).
Internet Connection
Exercise Resources
ItemDetails.cbl - COBOL program.
Exercise Definition
Create a new SDK Project.
Generate Java model (entity) from COBOL source file.
Develop unit tests on the fly.
Test the connectivity and data retrieval from the AS/400 host.
Step 1 – Create a New SDK Project
First, we will create a new SDK project using OpenLegacy IDE.
The purpose of the SDK project is to allow easy access to legacy backends, using standard and easy to use Java code.
Project Setup
Create a new OpenLegacy AS/400 RPC project.
Open the New Project Wizard:
File → New → OpenLegacy SDK Project
Define the Project Name as
as400-cobol-rpc-sdk
.Click at the Default Package field, to automatically fill it up.
Select AS/400 RPC as the backend and click Next.
Set the connection details to the backend based on the following parameters:
Host Name/IP:
as400.openlegacy.com
Code Page:
37
Username:
OPENLEGA1
Password:
OPENLEGA
Click Finish.
Testing the Configuration
Make sure your environment has no errors.
Do a Maven update if needed.
Do a project -> clean if needed (not Maven clean).
Congratulations! You are ready to start working on the API.
Step 2 – Generate Java Model (entity) from COBOL File
Let's create Java models out of our demo COBOL file.
Open ItemDetails.cbl located at
src/main/resources/sample
folder.Right-click on the file → OpenLegacy → Generate Model
In the 'Execute Action Path' field, write /QSYS.LIB/RMR2L1.LIB/FULLDETAIL.PGM
Check Generate JUnit Test checkbox
Click OK
Step 3 – Create a JUnit Test
OpenLegacy enables test-driven development by auto-generating test suites for each backend program (entities). We can extend this test suite with additional unit tests to validate our connectivity to the backend. The tests are auto-generated, and all you have to do is to provide a JSON format input and output to test againt the backend.
Open
src/test/resources/mock/ItemdetailsTest/test_itemdetailsTest_usecase_1.input.json
and change the itemNum field to1000
for the input.Open
src/test/resources/mock/ItemdetailsTest/test_itemdetailsTest_usecase_1.output.json
and paste the following JSON for the output:{ "dfhcommarea":{ "itemNum":1000, "itemRecord":{ "itemName":"Kid Guitar", "description":"Kids Guitar - Musical Toys", "weight":200 }, "shipping":{ "shippingMethod":"AIR MAIL", "days":2 } } }
Open
src/test/resources/mock/ItemdetailsTest/test_itemdetailsTest_usecase_2.input.json
and change the itemNum field to1004
for the input.Open
src/test/resources/mock/ItemdetailsTest/test_itemdetailsTest_usecase_2.output.json
and paste the following JSON, for the output:
{
"dfhcommarea":{
"itemNum":1004,
"itemRecord":{
"itemName":"Pig Bank",
"description":"Pig Saving Bank - Ceramics",
"weight":5000
},
"shipping":{
"shippingMethod":"AIR MAIL",
"days":2
}
}
}
5. Run the JUnit by Right-Clicking on testItemdeEXECUTE
→ Run As → JUnit Tests. If you followed all the steps correctly the tests should pass.
Step 4 – Create an API and a SDK
Open the New Project Wizard:
File → New → OpenLegacy API Project
Define the project name as
as400-cobol-rpc-api
.Click at the Default Package field, to automatically fill it up.
Press Next and add the SDK project that was created in Step 1 as the reference project.
Right-Click on the as400-cobol-rpc-api project → OpenLegacy → Generate API from SDK
Name the service
ItemDetails
.Select from the
ItemDetails
model theitemNum
as input and change its name toitemNumber
for better readability.Select
ItemDetails
model as output.Click OK
Step 5 - Run and Test your API
Right-Click on the as400-cobol-rpc-api project → OpenLegacy → Run Application
Open the browser on http://localhost:8080/swagger
Authorize through Oauth2
Client Id:
client_id
Client Secret:
client_secret
Click on the API we've created → Try it out
Set dummy item Number as input (for example
1000
).You should see a successful response returned directly from the AS/400 program
FULLDETAIL
{ "itemdetails": { "itemNum": 1000, "itemRecord": { "itemName": "Kid Guitar", "description": "Kids Guitar - Musical Toys", "weight": 200 }, "shipping": { "shippingMethod": "AIR MAIL", "days": 2 } } }