Package org.xrpl.xrpl4j.client
Interface JsonRpcClient
@Beta
public interface JsonRpcClient
A feign HTTP client for interacting with the rippled JSON RPC API. This client is strictly responsible for making
network calls and deserializing responses. All higher order functionality such as signing and serialization should be
implemented in a wrapper class.
Note: This client is currently marked as Beta
, and should be used as a reference implementation ONLY.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault void
checkForError
(com.fasterxml.jackson.databind.JsonNode response) Parse the response JSON to detect a possible error response message.static JsonRpcClient
construct
(okhttp3.HttpUrl rippledUrl) Constructs a new client for the given url.com.fasterxml.jackson.databind.JsonNode
postRpcRequest
(JsonRpcRequest rpcRequest) Send a POST request to the rippled server withrpcRequest
in the request body.default <T extends XrplResult>
Tsend
(JsonRpcRequest request, com.fasterxml.jackson.databind.JavaType resultType) Send a given request to rippled.default <T extends XrplResult>
Tsend
(JsonRpcRequest request, Class<T> resultType) Send a given request to rippled.
-
Field Details
-
logger
static final org.slf4j.Logger logger -
HEADER_ACCEPT
- See Also:
-
HEADER_CONTENT_TYPE
- See Also:
-
APPLICATION_JSON
- See Also:
-
objectMapper
static final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
SERVICE_UNAVAILABLE_STATUS
static final int SERVICE_UNAVAILABLE_STATUS- See Also:
-
RETRY_INTERVAL
-
-
Method Details
-
construct
Constructs a new client for the given url.- Parameters:
rippledUrl
- url for the faucet server.- Returns:
- A
JsonRpcClient
that can make request torippledUrl
-
postRpcRequest
Send a POST request to the rippled server withrpcRequest
in the request body.- Parameters:
rpcRequest
- A rippled JSON RPC API request object.- Returns:
- A
JsonNode
which can be manually parsed containing the response.
-
send
default <T extends XrplResult> T send(JsonRpcRequest request, Class<T> resultType) throws JsonRpcClientErrorException Send a given request to rippled.- Type Parameters:
T
- The extension ofXrplResult
corresponding to the request method.- Parameters:
request
- TheJsonRpcRequest
to send to the server.resultType
- The type ofXrplResult
that should be returned.- Returns:
- The
JsonRpcClient
representing the result of the request. - Throws:
JsonRpcClientErrorException
- If rippled returns an error message, or if the response could not be deserialized to the providedJsonRpcRequest
type.
-
send
default <T extends XrplResult> T send(JsonRpcRequest request, com.fasterxml.jackson.databind.JavaType resultType) throws JsonRpcClientErrorException Send a given request to rippled. Unlikesend(JsonRpcRequest, Class)
, this override requires aJavaType
as the resultType, which can be useful when expecting aXrplResult
with type parameters. In this case, you can use anObjectMapper
'sTypeFactory
to construct parameterized types.- Type Parameters:
T
- The extension ofXrplResult
corresponding to the request method.- Parameters:
request
- TheJsonRpcRequest
to send to the server.resultType
- The type ofXrplResult
that should be returned, converted to aJavaType
.- Returns:
- The
JsonRpcClient
representing the result of the request. - Throws:
JsonRpcClientErrorException
- If rippled returns an error message, or if the response could not be deserialized to the providedJsonRpcRequest
type.
-
checkForError
default void checkForError(com.fasterxml.jackson.databind.JsonNode response) throws JsonRpcClientErrorException Parse the response JSON to detect a possible error response message.- Parameters:
response
- TheJsonNode
containing the JSON response from rippled.- Throws:
JsonRpcClientErrorException
- If rippled returns an error message.
-