This class implements a bridge that unmarshalls JSON objects in JSON-RPC request format, invokes a method on the exported object, and then marshalls the resulting Java objects to JSON objects in JSON-RPC result format.
There is a global bridge singleton object that allows exporting classes and objects to all HTTP clients. In addition to this, an instance of the JSONRPCBridge can optionally be placed in a users' HttpSession object registered under the attribute "JSONRPCBridge" to allow exporting of classes and objects to specific users. A session specific bridge will delegate requests for objects it does not know about to the global singleton JSONRPCBridge instance.
Using session specific bridge instances can improve the security of applications by allowing exporting of certain objects only to specific HttpSessions as well as providing a convenient mechanism for JavaScript clients to access stateful data associated with the current user.
You can create a HttpSession specific bridge in JSP with the usebean tag:
<jsp:useBean id="JSONRPCBridge" scope="session" class="org.jabsorb.JSONRPCBridge" />
Then export an object for your JSON-RPC client to call methods on:
JSONRPCBridge.registerObject("test", testObject);
This will make available all public methods of the object as test.<methodnames>
to JSON-RPC clients. This approach should generally be performed after an authentication check to only export objects to clients that are authorised to use them.
Alternatively, the global bridge singleton object allows exporting of classes and objects to all HTTP clients. It can be fetched with JSONRPCBridge.getGlobalBridge()
.
To export all public instance methods of an object to all clients:
JSONRPCBridge.getGlobalBridge().registerObject("myObject", myObject);
To export all public static methods of a class to all clients:
JSONRPCBridge.getGlobalBridge().registerClass("MyClass", com.example.MyClass.class);
|
|
|
|
|
|
|
|