|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.thetransactioncompany.jsonrpc2.JSONRPC2Message
com.thetransactioncompany.jsonrpc2.JSONRPC2Notification
public class JSONRPC2Notification
Represents a JSON-RPC 2.0 notification.
Notifications provide a mean for calling a remote procedure without generating a response. Note that notifications are inherently unreliable as no confirmation is sent back to the caller.
Notifications have the same JSON structure as requests, except that they lack an identifier:
method The name of the remote method to call.
params The required method parameters (if any), which can
be packed into a JSON array or object.
jsonrpc A string indicating the JSON-RPC protocol version
set to "2.0".
Here is a sample JSON-RPC 2.0 notification string:
{
"method" : "progressNotify",
"params" : ["75%"],
"jsonrpc" : "2.0"
}
This class provides two methods to obtain a request object:
parse(java.lang.String) method, or
Example 1: Parsing a notification string:
String jsonString = "{\"method\":\"progressNotify\",\"params\":[\"75%\"],\"jsonrpc\":\"2.0\"}";
JSONRPC2Notification notification = null;
try {
notification = JSONRPC2Notification.parse(jsonString);
} catch (JSONRPC2ParseException e) {
// handle exception
}
Example 2: Recreating the above request:
String method = "progressNotify";
List params = new Vector();
params.add("75%");
JSONRPC2Notification notification = new JSONRPC2Notification(method, params);
System.out.println(notification);
The mapping between JSON and Java entities (as defined by the underlying JSON.simple library):
true|false <---> java.lang.Boolean
number <---> java.lang.Number
string <---> java.lang.String
array <---> java.util.List
object <---> java.util.Map
null <---> null
The JSON-RPC 2.0 specification and user group forum can be found here.
| Constructor Summary | |
|---|---|
JSONRPC2Notification(java.lang.String method)
Constructs a new JSON-RPC 2.0 notification with no parameters. |
|
JSONRPC2Notification(java.lang.String method,
java.util.List params)
Constructs a new JSON-RPC 2.0 notification with JSON array parameters. |
|
JSONRPC2Notification(java.lang.String method,
java.util.Map params)
Constructs a new JSON-RPC 2.0 notification JSON object parameters. |
|
| Method Summary | |
|---|---|
java.lang.String |
getMethod()
Gets the name of the requested method. |
java.lang.Object |
getParams()
Gets the notification parameters. |
JSONRPC2ParamsType |
getParamsType()
Gets the parameters type ( JSONRPC2ParamsType.ARRAY,
JSONRPC2ParamsType.OBJECT or
JSONRPC2ParamsType.NO_PARAMS). |
static JSONRPC2Notification |
parse(java.lang.String jsonString)
Parses a JSON-RPC 2.0 notification string. |
void |
setMethod(java.lang.String method)
Sets the name of the requested method. |
void |
setParams(java.lang.Object params)
Sets the notification parameters. |
org.json.simple.JSONObject |
toJSON()
Gets a JSON representation of the JSON-RPC 2.0 notification. |
| Methods inherited from class com.thetransactioncompany.jsonrpc2.JSONRPC2Message |
|---|
toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JSONRPC2Notification(java.lang.String method)
method - The name of the requested method.
public JSONRPC2Notification(java.lang.String method,
java.util.List params)
method - The name of the requested method.params - The notification parameters packed as a JSON array
(maps to java.util.List).
public JSONRPC2Notification(java.lang.String method,
java.util.Map params)
method - The name of the requested method.params - The notification parameters packed as a JSON object
(maps to java.util.Map).| Method Detail |
|---|
public static JSONRPC2Notification parse(java.lang.String jsonString)
throws JSONRPC2ParseException
jsonString - The JSON notification string, UTF-8 encoded.
JSONRPC2ParseException - With detailed message if the parsing
failed.public java.lang.String getMethod()
public void setMethod(java.lang.String method)
method - The method name.public JSONRPC2ParamsType getParamsType()
JSONRPC2ParamsType.ARRAY,
JSONRPC2ParamsType.OBJECT or
JSONRPC2ParamsType.NO_PARAMS).
public java.lang.Object getParams()
List if JSON array, Map
if JSON object, or null if none.public void setParams(java.lang.Object params)
params - The parameters. For a JSON array type pass a
List. For a JSON object pass a Map.
If there are no parameters pass null.public org.json.simple.JSONObject toJSON()
toJSON in class JSONRPC2Message
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||