diff --git a/consensusj-jsonrpc-cli/src/main/java/org/consensusj/jsonrpc/cli/BaseJsonRpcTool.java b/consensusj-jsonrpc-cli/src/main/java/org/consensusj/jsonrpc/cli/BaseJsonRpcTool.java index 1009883cb..c9f2c28ba 100644 --- a/consensusj-jsonrpc-cli/src/main/java/org/consensusj/jsonrpc/cli/BaseJsonRpcTool.java +++ b/consensusj-jsonrpc-cli/src/main/java/org/consensusj/jsonrpc/cli/BaseJsonRpcTool.java @@ -12,7 +12,6 @@ import org.consensusj.jsonrpc.AbstractRpcClient; import org.consensusj.jsonrpc.CompositeTrustManager; import org.consensusj.jsonrpc.JsonRpcClientJavaNet; -import org.consensusj.jsonrpc.JsonRpcException; import org.consensusj.jsonrpc.JsonRpcMessage; import org.consensusj.jsonrpc.JsonRpcRequest; import org.consensusj.jsonrpc.JsonRpcResponse; @@ -31,6 +30,7 @@ import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.List; +import java.util.concurrent.ExecutionException; import java.util.logging.Level; /** @@ -92,12 +92,13 @@ public void run(CommonsCLICall call) { JsonRpcRequest request = parser.parse(args); JsonRpcResponse response; try { - response = client.sendRequestForResponse(request); - } catch (JsonRpcException e) { - log.error("send exception: ", e); - throw new ToolException(1, e.getMessage()); - } catch (IOException e) { - log.error("send exception: ", e); + response = client.sendRequestForResponseAsync(request).get(); + } catch (ExecutionException ee) { + log.error("send execution exception: ", ee); + Throwable t = ee.getCause() != null ? ee.getCause(): ee; + throw new ToolException(1, t.getMessage()); + } catch (InterruptedException e) { + log.error("send interrupted exception: ", e); throw new ToolException(1, e.getMessage()); } String resultForPrinting = formatResponse(response, client.getMapper()); diff --git a/consensusj-jsonrpc/src/main/java/org/consensusj/jsonrpc/JacksonRpcClient.java b/consensusj-jsonrpc/src/main/java/org/consensusj/jsonrpc/JacksonRpcClient.java index 4cc62cd8c..eede9464b 100644 --- a/consensusj-jsonrpc/src/main/java/org/consensusj/jsonrpc/JacksonRpcClient.java +++ b/consensusj-jsonrpc/src/main/java/org/consensusj/jsonrpc/JacksonRpcClient.java @@ -68,7 +68,16 @@ default JsonRpcResponse sendRequestForResponse(JsonRpcRequest request, Ja * @throws JsonRpcStatusException JSON RPC status error */ default JsonRpcResponse sendRequestForResponse(JsonRpcRequest request) throws IOException, JsonRpcStatusException { - return syncGet(sendRequestForResponseAsync(request, responseTypeFor(JsonNode.class))); + return syncGet(sendRequestForResponseAsync(request)); + } + + /** + * Convenience method for requesting an asynchronous response with a {@link JsonNode} for the result. + * @param request The request to send + * @return A future JSON RPC Response with `result` of type {@code JsonNode} + */ + default CompletableFuture> sendRequestForResponseAsync(JsonRpcRequest request) { + return sendRequestForResponseAsync(request, responseTypeFor(JsonNode.class)); } private CompletableFuture sendRequestForResultAsync(JsonRpcRequest request, JavaType resultType) {