Package org.moera.lib.jsonrpc
Class OkHttpFetcher
java.lang.Object
org.moera.lib.jsonrpc.OkHttpFetcher
- All Implemented Interfaces:
Function<JsonRpcRequest,
JsonRpcResponse>
This class is responsible for fetching responses from a remote JSON-RPC server using the OkHttp client.
-
Constructor Summary
ConstructorsConstructorDescriptionOkHttpFetcher
(String url) Constructs an instance ofOkHttpFetcher
with the specified URL. -
Method Summary
Modifier and TypeMethodDescriptionapply
(JsonRpcRequest jsonRpcRequest) Processes a JSON-RPC request and fetches the corresponding JSON-RPC response from a remote server.
-
Constructor Details
-
OkHttpFetcher
Constructs an instance ofOkHttpFetcher
with the specified URL.- Parameters:
url
- the URL of the JSON-RPC server. It must be a valid HTTP or HTTPS URL and is used as the endpoint for all outgoing requests.
-
-
Method Details
-
apply
Processes a JSON-RPC request and fetches the corresponding JSON-RPC response from a remote server. The method uses the OkHttp client to send the request and parse the response.- Specified by:
apply
in interfaceFunction<JsonRpcRequest,
JsonRpcResponse> - Parameters:
jsonRpcRequest
- the JSON-RPC request to be sent to the remote server- Returns:
- the JSON-RPC response received from the server
- Throws:
JsonRpcException
- if the response cannot be parsedJsonRpcConnectionException
- if a network error occurs during the request execution
-