Class JsonRpcRequest

java.lang.Object
org.moera.lib.jsonrpc.JsonRpcRequest

public class JsonRpcRequest extends Object
Represents a JSON-RPC 2.0 request as specified by the JSON-RPC protocol. This class contains the structure required for a compliant JSON-RPC request.

JSON-RPC is a lightweight remote procedure call protocol encoded in JSON. Each request includes a method name, optional parameters, and an identifier that allows for asynchronous processing of requests.

The JsonRpcRequest class supports setting and retrieving the following properties:

- jsonrpc: Specifies the JSON-RPC protocol version (hardcoded to "2.0").
- method: Specifies the method to be invoked on the remote server.
- params: Provides the parameters to be passed to the method (if applicable).
- id: Identifies the request to match it with a corresponding response.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the identifier of the JSON-RPC request.
    Retrieves the JSON-RPC protocol version used in the request.
    Retrieves the name of the method to be invoked in the JSON-RPC request.
    com.fasterxml.jackson.databind.JsonNode
    Retrieves the parameters associated with the JSON-RPC request.
    void
    Sets the identifier for this JSON-RPC request.
    void
    setMethod(String method)
    Sets the name of the JSON-RPC method to be invoked in the request.
    void
    setParams(com.fasterxml.jackson.databind.JsonNode params)
    Sets the parameters to be passed to the remote method in a JSON-RPC request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonRpcRequest

      public JsonRpcRequest()
  • Method Details

    • getJsonrpc

      public String getJsonrpc()
      Retrieves the JSON-RPC protocol version used in the request.
      Returns:
      the JSON-RPC protocol version as a string, always "2.0".
    • getMethod

      public String getMethod()
      Retrieves the name of the method to be invoked in the JSON-RPC request.
      Returns:
      the method name as a string, which represents the procedure to be executed on the server.
    • setMethod

      public void setMethod(String method)
      Sets the name of the JSON-RPC method to be invoked in the request. The method name must correspond to a valid procedure on the JSON-RPC server.
      Parameters:
      method - the name of the method to be invoked. It cannot be null or empty and should adhere to the JSON-RPC protocol specifications.
    • getParams

      public com.fasterxml.jackson.databind.JsonNode getParams()
      Retrieves the parameters associated with the JSON-RPC request.
      Returns:
      the parameters of the request as a JsonNode, or null if no parameters are set.
    • setParams

      public void setParams(com.fasterxml.jackson.databind.JsonNode params)
      Sets the parameters to be passed to the remote method in a JSON-RPC request.
      Parameters:
      params - the parameters to be sent with the JSON-RPC request. This is expected to be a JSON structure represented by a JsonNode.
    • getId

      public Object getId()
      Retrieves the identifier of the JSON-RPC request.
      Returns:
      an Object representing the identifier of the request. The identifier is used to match the request with its corresponding response.
    • setId

      public void setId(Object id)
      Sets the identifier for this JSON-RPC request.
      Parameters:
      id - the identifier to associate with this request. It can be used to match the request with its corresponding response.