The Remote JSON-RPC Provider locates an exported service by module and then calls Java methods of this module.
Mapping Convention
To map a JSON-RPC method to a service, the provider uses the following convention:
<service_pid>/<method>
where <service_pid> stands for the persistent ID of the service and <method> stands for a name common to the JSON-RPC method and to the Java method of the service. For example the Event Admin Remote Handler supports the following JSON-RPC method:
EA/subscribe
EA is the service PID (abbreviated from Event Admin) and subscribe is the method.
Steps to Export a Service over JSON-RPC
Step 1: Implement the service to be exported:
Handle the request in your service – Implement a com.prosyst.mbs.services.remote.json.RemoteService. The provider will invoke the handleRequest method of the service – in its body process the passed parameters and return data if a return value is expected from the JSON-RPC method.
Have the request handled by the provider through its default Java reflection mechanism – Implement a service dedicating public methods that have the same names as the JSON-RPC methods you are planning to provide. For example, if you will export JSON-RPC HelloWorld/sayHello, then make sure that you have a public method sayHello in the service. Support the same number and proper data types of the Java method arguments as you are expecting to receive in the "params" property of the JSON-RPC method. Upon a JSON-RPC method call, the provider will locate the Java method of the service by name and will invoke it.
Step 2: Register the service in the OSGi framework with the following registration properties:
service.pid – Represented by the org.osgi.framework.Constants.SERVICE_PID field. Identifies the service to the JSON-RPC distribution provider.
service.exported.interfaces – Represented by the com.prosyst.mbs.services.remote.RemoteServiceConstants.SERVICE_EXPORTED_INTERFACES field. It marks the service for export and lists the interface under which the service can be exported. Use "*" to export all implemented interfaces by the service object.
(Optional) remote.exported.methods – Represented by the com.prosyst.mbs.services.remote.RemoteServiceConstants.CONFIG_EXPORTED_METHODS field. Lists the JSON-RPC methods that the service supports according to the <service>/<method> mapping convention. This property will be used by the system.listMethods JSON-RPC method.