Package org.consensusj.jsonrpc
Class JsonRpcClientHttpUrlConnection
java.lang.Object
org.consensusj.jsonrpc.JsonRpcClientHttpUrlConnection
- All Implemented Interfaces:
AsyncSupport
,JsonRpcTransport<JavaType>
JSON-RPC Client using
HttpURLConnection
formerly namedRpcClient
.
This is a concrete class with generic JSON-RPC functionality, it implements the abstract
method JsonRpcTransport.sendRequestForResponseAsync(JsonRpcRequest, Type)
using HttpURLConnection
.
Uses strongly-typed POJOs representing JsonRpcRequest
and JsonRpcResponse
. The
response object uses a parameterized type for the object that is the actual JSON-RPC `result`.
Using strong types and Jackson to serialize/deserialize to/from strongly-typed POJO's without
using intermediate `Map` or `JsonNode` types.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.consensusj.jsonrpc.AsyncSupport
AsyncSupport.ThrowingSupplier<T>, AsyncSupport.TransientErrorFilter
-
Constructor Summary
ConstructorDescriptionJsonRpcClientHttpUrlConnection
(ObjectMapper mapper, SSLContext sslContext, URI server, String rpcUser, String rpcPassword) -
Method Summary
Modifier and TypeMethodDescriptionGet the URI of the server this client connects to<R> JsonRpcResponse
<R> sendRequestForResponse
(JsonRpcRequest request, JavaType responseType) Send a JSON-RPC request to the server and return a JSON-RPC response.<R> CompletableFuture
<JsonRpcResponse<R>> sendRequestForResponseAsync
(JsonRpcRequest request, JavaType responseType) Send aJsonRpcRequest
for aJsonRpcResponse
asynchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.consensusj.jsonrpc.AsyncSupport
getDefaultAsyncExecutor, supplyAsync, supplyAsync
Methods inherited from interface org.consensusj.jsonrpc.JsonRpcTransport
syncGet
-
Constructor Details
-
JsonRpcClientHttpUrlConnection
public JsonRpcClientHttpUrlConnection(ObjectMapper mapper, SSLContext sslContext, URI server, String rpcUser, String rpcPassword)
-
-
Method Details
-
getServerURI
Get the URI of the server this client connects to- Specified by:
getServerURI
in interfaceJsonRpcTransport<JavaType>
- Returns:
- Server URI
-
sendRequestForResponse
public <R> JsonRpcResponse<R> sendRequestForResponse(JsonRpcRequest request, JavaType responseType) throws IOException, JsonRpcStatusException Send a JSON-RPC request to the server and return a JSON-RPC response.- Specified by:
sendRequestForResponse
in interfaceJsonRpcTransport<JavaType>
- Type Parameters:
R
- Type of result object- Parameters:
request
- JSON-RPC requestresponseType
- Response type to deserialize to- Returns:
- JSON-RPC response
- Throws:
IOException
- when thrown by the underlying HttpURLConnectionJsonRpcStatusException
- when the HTTP response code is other than 200
-
sendRequestForResponseAsync
public <R> CompletableFuture<JsonRpcResponse<R>> sendRequestForResponseAsync(JsonRpcRequest request, JavaType responseType) Description copied from interface:JsonRpcTransport
Send aJsonRpcRequest
for aJsonRpcResponse
asynchronously.- Specified by:
sendRequestForResponseAsync
in interfaceJsonRpcTransport<JavaType>
- 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`
-