Server Reference Guide : 11. JSON-RPC 2.0 Interface : Creating a Sample OpenROAD Server Application with JSON-RPC Support
 
Share this page                  
Creating a Sample OpenROAD Server Application with JSON-RPC Support
1. Using Workbench, create a new OpenROAD application named testapp with a Database Connection “None.”
2. Add a new Ghost Frame Component named startingghost.
3. Set startingghost as the Starting Component of the testapp application.
4. Add a new 4GL Procedure named “add,” which will be called using the JSON-RPC interface.
5. Implement the procedure with two integer parameters “val1” and “val2” and returning val1+val2 as an integer.
PROCEDURE add (
  val1 = INTEGER NOT NULL,
  val2 = INTEGER NOT NULL
)=
{
  RETURN val1+val2;
}
6. Create testapp.json using the JsonConfig4App utility for the “add” 4GL procedure.
7. Copy testapp.json into %II_SYSTEM%\ingres\files\orjsonconfig.
8. Create an image of the testapp application as testapp.img.
9. Copy testapp.img into the directory specified by the II_W4GLAPPS_DIR environment variable. (See Environment Variables for All Platforms in the Workbench User Guide.)
10. Register the testapp application in Visual OpenROAD Server Administrator.
11. Add the servlet-mapping for testapp like one added for jsonrpctest in web.xml under the Tomcat OpenROAD webapp (for example, in C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\openroad\WEB-INF\web.xml). For example:
<servlet-mapping>
  <servlet-name>OpenROADJSONRPC</servlet-name>
  <url-pattern>/testapp</url-pattern>
</servlet-mapping>
12. Restart Tomcat and the OpenROAD Application Server.
13. Test the servlet using your Tomcat webapp URL such as http://localhost:8080/openroad/testapp.
14. Send the following JSON-RPC request for the “add” procedure:
{
  "jsonrpc": "2.0",
  "method": "add",
  "params": {
    "val1": 1,
    "val2": 2
  },
  "id": 1
}
The JSON-RPC response should be:
{
  "result": 3,
  "id": 1,
  "jsonrpc": "2.0"
}
You can execute the previous JSON-RPC request using a test user frame of the jsonrpcservertest application.