Package org.consensusj.jsonrpc
Interface JsonRpcTransport<T extends Type>
- All Superinterfaces:
AsyncSupport
- All Known Subinterfaces:
JsonRpcClient<T>
- All Known Implementing Classes:
BitcoinClient
,BitcoinExtendedClient
,DefaultRpcClient
,EthereumClient
,JsonRpcClientHttpUrlConnection
,JsonRpcClientJavaNet
,NamecoinClient
,RxBitcoinClient
Defines the interface for a network-layer implementation of a JSON-RPC client.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.consensusj.jsonrpc.AsyncSupport
AsyncSupport.ThrowingSupplier<T>, AsyncSupport.TransientErrorFilter
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
base64Encode
(String authString) Encode username password as Base64 for basic authenticationstatic SSLContext
Return the defaultSSLContext
without declaring a checked exceptionGet the URI of the remote serverdefault <R> JsonRpcResponse
<R> sendRequestForResponse
(JsonRpcRequest request, T responseType) Send aJsonRpcRequest
for aJsonRpcResponse
<R> CompletableFuture
<JsonRpcResponse<R>> sendRequestForResponseAsync
(JsonRpcRequest request, T responseType) Send aJsonRpcRequest
for aJsonRpcResponse
asynchronously.default <R> R
syncGet
(CompletableFuture<R> future) Synchronously complete a JSON-RPC request by callingCompletableFuture.get()
, unwrapping nestedJsonRpcException
orIOException
fromExecutionException
.Methods inherited from interface org.consensusj.jsonrpc.AsyncSupport
getDefaultAsyncExecutor, supplyAsync, supplyAsync
-
Method Details
-
getServerURI
Get the URI of the remote server- Returns:
- URI of remote server
-
sendRequestForResponse
default <R> JsonRpcResponse<R> sendRequestForResponse(JsonRpcRequest request, T responseType) throws IOException, JsonRpcStatusException Send aJsonRpcRequest
for aJsonRpcResponse
Synchronous subclasses should override this method to prevent
CompletableFuture.supplyAsync(Supplier)
from being called twice whenAsyncSupport
is being used. Eventually we'll migrate more of the codebase to native async, and then we won't have to worry about callingsupplyAsync
twice.- Type Parameters:
R
- Type of result object- Parameters:
request
- The request to sendresponseType
- The response type expected (used by Jackson for conversion)- Returns:
- A JSON RPC Response with `result` of type `R`
- Throws:
IOException
- network errorJsonRpcStatusException
- JSON RPC status error
-
sendRequestForResponseAsync
<R> CompletableFuture<JsonRpcResponse<R>> sendRequestForResponseAsync(JsonRpcRequest request, T responseType) Send aJsonRpcRequest
for aJsonRpcResponse
asynchronously.- Type Parameters:
R
- Type of result object- Parameters:
request
- The request to sendresponseType
- The response type expected (used by Jackson for conversion)- Returns:
- A future JSON RPC Response with `result` of type `R`
-
syncGet
Synchronously complete a JSON-RPC request by callingCompletableFuture.get()
, unwrapping nestedJsonRpcException
orIOException
fromExecutionException
.- Type Parameters:
R
- The expected result type- Parameters:
future
- TheCompletableFuture
(result of JSON-RPC request) to unwrap- Returns:
- A JSON-RPC result
- Throws:
IOException
- IfCompletableFuture.get()
threwExecutionException
caused byIOException
JsonRpcException
- IfCompletableFuture.get()
threwExecutionException
caused byJsonRpcException
RuntimeException
- IfCompletableFuture.get()
threwInterruptedException
or otherExecutionException
.
-
base64Encode
Encode username password as Base64 for basic authenticationWe're using
Base64
, which requires Android 8.0 or later.- Parameters:
authString
- An authorization string of the form `username:password`- Returns:
- A compliant Base64 encoding of `authString`
-
getDefaultSSLContext
Return the defaultSSLContext
without declaring a checked exception- Returns:
- The default
SSLContext
-