|
||||||||
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.
An instance of the JSONRPCBridge object is automatically placed in the HttpSession object registered under the attribute "JSONRPCBridge" by the JSONRPCServlet. The bridge is implemented as session specific to improve the security of applications by allowing exporting of object methods only to specific HttpSessions. To use the bridge to allow calling of Java methods you can easily access the HttpSession specific bridge in JSP using the usebean tag. eg.<jsp:useBean id="JSONRPCBridge" scope="session"
class="com.metaparadigm.jsonrpc.JSONRPCBridge" />
Then export the object you wish to call methods on. eg.
JSONRPCBridge.registerObject("test", testObject);
This will make available all methods of the object as
test.<methodnames>
to JSON-RPC clients. This method
should generally be performed after an authentication check to only
export specific objects to clients that are authorised to use them.
There exists a global bridge singleton object that will allow exporting
objects to all HTTP clients. This can be used for registering factory
classes although care must be taken with authentication as these objects
will be accessible to all clients.
Constructor Summary | |
---|---|
JSONRPCBridge()
|
|
JSONRPCBridge(boolean useDefaultSerializers)
|
Method Summary | |
---|---|
JSONRPCResult |
call(java.lang.Object[] context,
JSONObject jsonReq)
|
void |
enableReferences()
|
static JSONRPCBridge |
getGlobalBridge()
This method retreieves the global bridge singleton. |
JSONSerializer |
getSerializer()
|
java.lang.Class |
lookupClass(java.lang.String name)
Lookup a class that is registered with this bridge. |
java.lang.Object |
lookupObject(java.lang.String 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 s)
|
void |
setDebug(boolean debug)
|
void |
setSerializer(JSONSerializer ser)
|
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()
public JSONRPCBridge(boolean useDefaultSerializers)
Method Detail |
---|
public JSONRPCResult call(java.lang.Object[] context, JSONObject jsonReq)
public void enableReferences() throws java.lang.Exception
java.lang.Exception
public static JSONRPCBridge getGlobalBridge()
public JSONSerializer getSerializer()
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.String 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
name
- The named prefix to export the class asclazz
- 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 transportpublic void registerObject(java.lang.Object key, java.lang.Object o)
<key>.<methodnames>
to JSON-RPC clients.
key
- The named prefix to export the object aso
- The object instance to be called uponpublic 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 s) throws java.lang.Exception
java.lang.Exception
public void setDebug(boolean debug)
public void setSerializer(JSONSerializer ser)
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 |