Class 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 the request() 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 the notify() methods.
    • 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,
                              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 name
        params - the parameters
        Returns:
        the result
        Throws:
        IOException - if an error occurs while sending or receiving
        JsonRpcException - if the remote method returned an error response
        ParseException - 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 name
        params - the parameters
        Returns:
        the result
        Throws:
        IOException - if an error occurs while sending or receiving
        JsonRpcException - if the remote method returned an error response
        ParseException - 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 name
        params - 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 name
        params - the parameters
        Throws:
        IOException - if an error occurs while sending the notification