Server Reference Guide : JSON-RPC 2.0 Interface : Sending JSON-RPC Requests to the Server Application : Using the JsonRpcRequest Method of the RemoteServer Class
 
Share this page          
Using the JsonRpcRequest Method of the RemoteServer Class
A client can invoke the JsonRpcRequest() method (“jsonRpcRequest” for the Java interface) of the RemoteServer class provided in the supported interfaces (OpenROAD, COM, Java, and .NET).
The method can be used on a server connection through COM, DCOM, HTTP, or HTTPS.
To use this method over HTTP or HTTPS, the client must establish the connection with the Initiate() method using “http-jsonrpc” routing and the location pointing to the OpenROADJSONRPC servlet.
The JsonRpcRequest() method takes a string parameter containing the JSON-RPC 2.0 request:
OpenROAD: StringObject
COM: BSTR
C#: string
Java: String
It returns a string containing the JSON-RPC 2.0 response.
For more information, see the RemoteServer Initiate Method and JsonRpcRequest Method in the Language Reference Guide.
Also see the OpenROAD JSON examples available here: https://github.com/ActianCorp/OpenROAD_json/tree/master/openroad.
Example in OpenROAD 4GL: Connection with “http-jsonrpc” routing
declare
    request=StringObject;
    response=StringObject DEFAULT NULL;
enddeclare
{
    CurRemoteServer.Initiate(image = '', type = RP_SHARED,
        location='http://myserver:8080/openroad/jsonrpcservertest',
        routing='http-jsonrpc');
    request.Value = '{"jsonrpc":"2.0", "id":1, "method":"subtract", ' + 
        '"params":{"subtrahend":23.4, "minuend":42.8}}';
    response = CurRemoteServer.JsonRpcRequest(request=request);
    MESSAGE 'RESPONSE:' + HC_NEWLINE + response.Value;
    CurRemoteServer.Release();
}
Example in Java: Using a COM connection
import com.ca.openroad.*;
class jsonrpcdemo {
   public static void main(String[] args) throws COMException
    {
        RemoteServer rso = null;
        try
        {
            String request = "{\"jsonrpc\":\"2.0\", \"id\":2, " +
                "\"method\":\" subtract \", " +
                "\"params\":{\" subtrahend \":23.4, \" minuend \":42.8}}";
            rso = new RemoteServer();
            rso.connect("jsonrpcservertest", null, null);
            System.out.println("#### Request ####");
            System.out.println(request);
            String response = rso.jsonRpcRequest(request);
            System.out.println("#### Response ####");
            System.out.println(response);
            rso.disconnect();
        }
        finally
        {
            if (rso != null)
            {
                rso.release();
            }
        }
    }
}