Package eu.woolplatform.utils.json.rpc
Class JsonRpcHttp
- java.lang.Object
-
- eu.woolplatform.utils.json.rpc.JsonRpcHttp
-
public class JsonRpcHttp extends Object
This class provides JSON-RPC over a HTTP connection. It can only be used for outgoing requests and notifications. This class was designed to make the remote procedure calls look like normal method calls. You can send requests with therequest()methods. They wait for the response and return it as soon as it's received. In case of an error, they throw an exception. Notifications are like void methods. You can send notifications with thenotify()methods.
-
-
Constructor Summary
Constructors Constructor Description JsonRpcHttp(URL url)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes any open connections.voidnotify(String methodName)Sends a notification without parameters.voidnotify(String methodName, Object... params)Sends a notification with parameters as a JSON array.voidnotify(String methodName, Map<String,?> params)Sends a notification with parameters as a JSON object.Objectrequest(String methodName)Sends a request without parameters.Objectrequest(String methodName, Object... params)Sends a request with parameters as a JSON array.Objectrequest(String methodName, Map<String,?> params)Sends a request with parameters as a JSON object.
-
-
-
Field Detail
-
LOGTAG
public static final String LOGTAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JsonRpcHttp
public JsonRpcHttp(URL url)
Constructs a new instance.- Parameters:
url- the URL (e.g. http://localhost:8080/jsonrpc)
-
-
Method Detail
-
close
public void close()
Closes any open connections.
-
request
public Object request(String methodName) throws IOException, JsonRpcException, ParseException
Sends a request without parameters. The result object is obtained by parsing the JSON result string.- Parameters:
methodName- the method name- Returns:
- the result
- Throws:
IOException- if an error occurs while sending or receivingJsonRpcException- if the remote method returned an error responseParseException- if the server response can't be parsed
-
request
public Object request(String methodName, Map<String,?> params) throws IOException, JsonRpcException, ParseException
Sends a request with parameters as a JSON object. This method waits for the result and returns it. The result object is obtained by parsing the JSON result string.- Parameters:
methodName- the method nameparams- the parameters- Returns:
- the result
- Throws:
IOException- if an error occurs while sending or receivingJsonRpcException- if the remote method returned an error responseParseException- if the server response can't be parsed
-
request
public Object request(String methodName, Object... params) throws IOException, JsonRpcException, ParseException
Sends a request with parameters as a JSON array. This method waits for the result and returns it. The result object is obtained by parsing the JSON result string.- Parameters:
methodName- the method nameparams- the parameters- Returns:
- the result
- Throws:
IOException- if an error occurs while sending or receivingJsonRpcException- if the remote method returned an error responseParseException- if the server response can't be parsed
-
notify
public void notify(String methodName) throws IOException
Sends a notification without parameters.- Parameters:
methodName- the method name- Throws:
IOException- if an error occurs while sending the notification
-
notify
public void notify(String methodName, Map<String,?> params) throws IOException
Sends a notification with parameters as a JSON object.- Parameters:
methodName- the method nameparams- the parameters- Throws:
IOException- if an error occurs while sending the notification
-
notify
public void notify(String methodName, Object... params) throws IOException
Sends a notification with parameters as a JSON array.- Parameters:
methodName- the method nameparams- the parameters- Throws:
IOException- if an error occurs while sending the notification
-
-