|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.metaparadigm.jsonrpc.JSONRPCBridge
public class JSONRPCBridge
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="com.metaparadigm.jsonrpc.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);
| Constructor Summary | |
|---|---|
JSONRPCBridge()
Default Constructor. |
|
| Method Summary | |
|---|---|
JSONRPCResult |
call(java.lang.Object[] context,
JSONObject jsonReq)
Call a method using a JSON-RPC request object. |
JSONRPCBridgeState |
getBridgeState()
Get the JSONRPCBridgeState object associated with this bridge. |
CallbackController |
getCallbackController()
Get the CallbackController object associated with this bridge. |
static JSONRPCBridge |
getGlobalBridge()
This method retrieves the global bridge singleton. |
java.util.HashMap |
getReferenceMap()
Gets the map of referenced objects used by this bridge. |
static JSONSerializer |
getSerializer()
Get the global JSONSerializer object. |
boolean |
isCallableReference(java.lang.Class clazz)
Check whether a class is registered as a callable reference type. |
boolean |
isReference(java.lang.Class clazz)
Check whether a class is registered as a reference type. |
java.lang.Class |
lookupClass(java.lang.String name)
Lookup a class that is registered with this bridge. |
java.lang.Object |
lookupObject(java.lang.Object key)
Lookup an object that is registered with this bridge. |
void |
registerCallableReference(java.lang.Class clazz)
Registers a class to be returned as a callable reference. |
void |
registerCallback(InvocationCallback callback,
java.lang.Class contextInterface)
Registers a callback to be called before and after method invocation |
void |
registerClass(java.lang.String name,
java.lang.Class clazz)
Registers a class to export static methods. |
static void |
registerLocalArgResolver(java.lang.Class argClazz,
java.lang.Class contextInterface,
LocalArgResolver argResolver)
Registers a Class to be removed from the exported method signatures and instead be resolved locally using context information from the transport. |
void |
registerObject(java.lang.Object key,
java.lang.Object o)
Registers an object to export all instance methods and static methods. |
void |
registerObject(java.lang.Object key,
java.lang.Object o,
java.lang.Class interfaceClass)
Registers an object to export all instance methods defined by interfaceClass. |
void |
registerReference(java.lang.Class clazz)
Registers a class to be returned by reference and not by value as is done by default. |
void |
registerSerializer(Serializer serializer)
Register a new serializer on this bridge. |
void |
setBridgeState(JSONRPCBridgeState state)
Set the JSONRPCBridgeState object for this bridge. |
void |
setCallbackController(CallbackController cbc)
Set the CallbackController object for this bridge. |
void |
setDebug(boolean debug)
Enable or disable debugging message from this bridge instance. |
void |
setExceptionTransformer(ExceptionTransformer exceptionTransformer)
|
static void |
setSerializer(JSONSerializer ser)
Set the global JSONSerializer object. |
void |
unregisterCallback(InvocationCallback callback,
java.lang.Class contextInterface)
Unregisters a callback |
void |
unregisterClass(java.lang.String name)
Unregisters a class exported with registerClass. |
static void |
unregisterLocalArgResolver(java.lang.Class argClazz,
java.lang.Class contextInterface,
LocalArgResolver argResolver)
Unregisters a LocalArgResolver. |
void |
unregisterObject(java.lang.Object key)
Unregisters an object exported with registerObject. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JSONRPCBridge()
| Method Detail |
|---|
public JSONRPCResult call(java.lang.Object[] context,
JSONObject jsonReq)
context - The transport context (the HttpServletRequest object in the
case of the HTTP transport).jsonReq - The JSON-RPC request structured as a JSON object tree.
public JSONRPCBridgeState getBridgeState()
public CallbackController getCallbackController()
public static JSONRPCBridge getGlobalBridge()
public java.util.HashMap getReferenceMap()
public static JSONSerializer getSerializer()
public boolean isCallableReference(java.lang.Class clazz)
clazz - The class object to check is a callable reference.public boolean isReference(java.lang.Class clazz)
clazz - The class object to check is a reference.
public java.lang.Class lookupClass(java.lang.String name)
throws java.lang.Exception
name - The registered name of the class to lookup.
java.lang.Exception
public java.lang.Object lookupObject(java.lang.Object key)
throws java.lang.Exception
key - The registered name of the object to lookup.
java.lang.Exception
public void registerCallableReference(java.lang.Class clazz)
throws java.lang.Exception
{ "javaClass":"com.metaparadigm.test.Bar",
"objectID":4827452,
"JSONRPCType":"CallableReference" }
clazz - The class object that should be marshalled as a callable
reference.
java.lang.Exception
public void registerCallback(InvocationCallback callback,
java.lang.Class contextInterface)
callback - The object implementing the InvocationCallback InterfacecontextInterface - The type of transport Context interface the callback is
interested in eg. HttpServletRequest.class for the servlet
transport.
public void registerClass(java.lang.String name,
java.lang.Class clazz)
throws java.lang.Exception
clazz - The class to export static methods from.
java.lang.Exception
public static void registerLocalArgResolver(java.lang.Class argClazz,
java.lang.Class contextInterface,
LocalArgResolver argResolver)
argClazz - The class to be resolved locallyargResolver - The user defined class that resolves the and returns the
method argument using transport context informationcontextInterface - The type of transport Context object the callback is
interested in eg. HttpServletRequest.class for the servlet
transport
public void registerObject(java.lang.Object key,
java.lang.Object o)
<key>.<methodnames> to JSON-RPC clients.
Calling registerObject for a name that already exists will replace
the existing entry.
key - The named prefix to export the object aso - The object instance to be called upon
public void registerObject(java.lang.Object key,
java.lang.Object o,
java.lang.Class interfaceClass)
<key>.<methodnames> to JSON-RPC clients.
key - The named prefix to export the object aso - The object instance to be called uponinterfaceClass - The type that this object should be registered as.
This can be used to restrict the exported methods to the methods
defined in a specific superclass or interface.
public void registerReference(java.lang.Class clazz)
throws java.lang.Exception
{ "javaClass":"com.metaparadigm.test.Foo",
"objectID":5535614,
"JSONRPCType":"Reference" }
clazz - The class object that should be marshalled as a reference.
java.lang.Exception
public void registerSerializer(Serializer serializer)
throws java.lang.Exception
serializer - A class implementing the Serializer interface (usually derived
from AbstractSerializer).
java.lang.Exceptionpublic void setBridgeState(JSONRPCBridgeState state)
state - the JSONRPCBridgeState object to be set for this bridge.public void setCallbackController(CallbackController cbc)
cbc - the CallbackController object to be set for this bridge.public void setDebug(boolean debug)
debug - flag to enable or disable debugging messagespublic void setExceptionTransformer(ExceptionTransformer exceptionTransformer)
public static void setSerializer(JSONSerializer ser)
ser - the global JSONSerializer object.
public void unregisterCallback(InvocationCallback callback,
java.lang.Class contextInterface)
callback - The previously registered InvocationCallback objectcontextInterface - The previously registered transport Context interface.
public void unregisterClass(java.lang.String name)
throws java.lang.Exception
name - The registered name of the class to unexport static methods
from.
java.lang.Exception
public static void unregisterLocalArgResolver(java.lang.Class argClazz,
java.lang.Class contextInterface,
LocalArgResolver argResolver)
argClazz - The previously registered local classargResolver - The previously registered LocalArgResolver objectcontextInterface - The previously registered transport Context interface.public void unregisterObject(java.lang.Object key)
key - The named prefix of the object to unexport
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||